Write a program to check presence of a file in a present working directory.
#include<stdio.h> int Check_Presence_of_File(char*); enum File_Status{IS_PRESENT,IS_NOT_PRESENT}; int main() { char fileName[32]; printf("Enter file Name = "); scanf("%[^\n]",fileName); if(IS_PRESENT == Check_Presence_of_File(fileName)) printf("File is present in this directory\n"); else printf("File is not present in this directory\n"); return 0; } int Check_Presence_of_File(char* p) { FILE *fp; fp = fopen(p,"r"); if(fp == NULL) return IS_NOT_PRESENT; else return IS_PRESENT; }
Note: File name data is present in the current working directory.
lot to learn blackBerry iphone incredible india
Output
Enter file Name = data File is present in this directory
Enter file Name = nons File is not present in this directory