Printing to file -- Not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BOMEz
    New Member
    • Dec 2007
    • 40

    Printing to file -- Not working

    I'm trying to print to file and for some reason it just won't work out. I can read a file with no problems, but printing to it just comes up blank time and time again.

    Can someone kindly point out what is wrong with this code?

    Code:
    FILE *out;
    out = fopen("C:\report.txt","w");
    	if (!out)
    	{
    		printf ("***COULD NOT FIND FILE***\n");
    		exit(1);
    	}
    	fprintf (out,"TEST");
    I do not fall into this if loop at all, yet the file still comes out empty
  • Savage
    Recognized Expert Top Contributor
    • Feb 2007
    • 1759

    #2
    Originally posted by BOMEz
    I'm trying to print to file and for some reason it just won't work out. I can read a file with no problems, but printing to it just comes up blank time and time again.

    Can someone kindly point out what is wrong with this code?

    Code:
    FILE *out;
    out = fopen("C:\report.txt","w");
    	if (!out)
    	{
    		printf ("***COULD NOT FIND FILE***\n");
    		exit(1);
    	}
    	fprintf (out,"TEST");
    I do not fall into this if loop at all, yet the file still comes out empty
    You are not closing file after you are finished doing stuff with it,and '\' in your path gets interpreted by a compiler as a '\r' escape character,you will need to use '\\' instead of it.

    Comment

    • BOMEz
      New Member
      • Dec 2007
      • 40

      #3
      Originally posted by Savage
      You are not closing file after you are finished doing stuff with it,and '\' in your path gets interpreted by a compiler as a '\r' escape character,you will need to use '\\' instead of it.
      Wow I spent two hours trying to figure it out, only to forget that "\" needs to be double if you actually intend to use it....I love programming....

      Thanks for helping me out.

      Comment

      Working...