unable to read a file in c language. it creates a new file instead of reading it -
I have created a file in the directory and want to read it. I am using the following code to open and read a file in C-language but instead of reading the old file, I create a new file. int main () {FILE * file; File = FOPAN ("file", "R +"); // file reading fclose code (file); Return (0); 'r +' mode to open Are using the file. This creates a new file if the directory does not already exist. See the following code for your help. int main () {FILE * file; File = FOPAN ("file", "r"); If (file! == NULL) // read the second file and printf ("Error reading file"); Fclose (file); Return (0); } Also check the file name that you are using in the phpon () function. This case is sensitive and also checks the extension of that file; .txt or .data or what ever eg .; file = fopen ("file.txt", "r");