Thread: Writting to a text file

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    8

    Writting to a text file

    Hi,

    I have a liitle program the stores information in arrays.

    I have it to work fine and display the information but I am trying to make it write the information to a text file as well.

    The code i have...

    Code:
    void CreateATextFile(void)
    {
    	/* local variable definition */
    	int i = 0;
    
    	/* Open the customer file...If it doesn't exist create it... */
    	FILE *RecordFile;
    	RecordFile = fopen("RecordFile.txt", "a++");
    
    	/* Send data for each structure to the file */
    	for(i = 0; i < c; i++)
    	{
    		fprintf(RecordFile,"Customer Record: = %d\n", i);
    		fprintf(RecordFile,"\tName:\t%s\n", customer[i].Name);
    		fprintf(RecordFile,"\tAge:\t%d\n", customer[i].Age);
    		fprintf(RecordFile,"Policy\n");
    		fprintf(RecordFile,"\tType:\t%s\n", customer[i].Policy);
    		fprintf(RecordFile,"\tPremium:%c%d\n", 163, customer[i].Premium);
    		fprintf(RecordFile,"\tExcess:\t%c%d\n\n", 163, customer[i].Excess);
    	}
    	fprintf(RecordFile,"*************************************\n\n");
    
    	fclose(RecordFile);
    
    } /* End of create a text file */
    Everything seems to work fine but it does not enter the information just the line of *'s. I cant see a problem and the are no error's or warning when I compile.

    Any help would be great.

    Thanks

    Andy

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Well, the most obvious thing would be to make sure c isn't 0 when entering the function. Is it a global somewhere that is supposed to be set to the number of entries in the array?
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  4. How to use FTP?
    By maxorator in forum C++ Programming
    Replies: 8
    Last Post: 11-04-2005, 03:17 PM
  5. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 04:49 PM