Hi all,
I am trying to read text from a file. I have saved the file at c:\myfile.txt for some unknown reason my program cannot read the file and I am not sure what I am doing wrong.
Can anyone help?
Code:
int main(void) {
FILE *myfile;
char content [100]; // the variable will contain 101 characters
int i;
myfile = fopen("c:\\myfile.txt", "rt"); // rt for read text
fscanf(myfile,"%s",content);
if(myfile == NULL){// exception if file not found
printf("File not found");
}
else
printf("The contents of the file are: %s",content); // print file contents if file found
fclose(myfile); // close file
return(0);
}