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");    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -