file not opening in C - TechRepublic
General discussion
February 8, 2006 at 05:18 AM
chaos buddha

file not opening in C

by chaos buddha . Updated 20 years, 3 months ago

I wanted to display the contents of any file on the console;so I wrote the following piece of C code:
#include #include
int main(void)
{
FILE *P;int c;
P=fopen(“path”,”mode”);
if(P==NULL){puts(“can’t open file”); getch();return 0;};
else do{
c=getc(P);
printf(“%c”,c);
}while(c!=EOF);
getch();fclose(P);return 0;
}
PROBLEM:- I get the output “can’t open file” Tried various combinations of file extensions/folders(like C:\TC\BIN\file.txt) but that didn’t help….
Also I wud like to create an application using the code above so that when the file is clicked,the text goes to console.I don’t wan’t to create a zipped file but kindda “embed” it into code.Also such a file must not EAT RAM…

This discussion is locked

All Comments