Problems of looping in saving to a text file

Reply

Join Date: Oct 2004
Posts: 11
Reputation: kimimaro is an unknown quantity at this point 
Solved Threads: 0
kimimaro kimimaro is offline Offline
Newbie Poster

Problems of looping in saving to a text file

 
0
  #1
Oct 30th, 2004
hi below is my save function that is used to placed data from the C program to a text file for future usage.

void save()
{

	FILE *save;
   int i = 0;
	save=fopen("employeerecord.txt", "a+");

	do
	{
		if(strcmp(record[i].ID, "")!=0)
		{
			if(i!=0)
         fprintf(save, "\n");
			fprintf(save, "%s %s %s %s %s ", record[i].ID, record[i].Name, record[i].Name2, record[i].Department[storage], record[i].Post[rank]);

		}
		else
		{
			break;
		}
		i++;
	}while(i<500);
	fclose(save);
}
There was no problem for me to save the first employee and the second but when adding the 3rd employee data, this is what appears in the text file :

1121 sonia cooling Management Maid 1121 sonia cooling Management Maid
1331 mustapha jamal Management Office_Boy 1121 sonia cooling Management Maid
1121 sonia cooling Management Maid
1331 mustapha jamal Management Office_Boy
1111 cheng kahhin Administration Chief_Executive_Officer


Sonia is the 1st employee I add, mustapha second and cheng the third. My data are ID firstname secondname department post and it seems the 1st and second loops before going to the third pls help if the problem is in the save function if not its in the add_function but I want to make sure if its the save function
Last edited by alc6379; Oct 30th, 2004 at 3:26 pm.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,541
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 704
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Problems of looping in saving to a text file

 
0
  #2
Oct 30th, 2004
You have too many global variables for me to guess accurately what the problem is, but my first suggestion would be to make sure that your strings are terminated with a null character ('\0').
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC