Write a program to check presence of a file, input has to given a load time.
#include<stdio.h> int Check_Presence_of_File(char*); enum File_Status{IS_PRESENT,IS_NOT_PRESENT}; int main(int argc,char**argv) { if(argc != 2) { printf("Usage:./a.out filename\n"); return 0; } if(IS_PRESENT == Check_Presence_of_File(argv[1])) 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.
cat data lot to learn blackBerry iphone incredible india
Output
./a.out Usage:./a.out filename
./a.out data File is present in this directory
./a.out nsdsd File is not present in this directory