here is the code I am having a problem with, I cannot get the save or load of my files to work. Can anyone help me find my errors? I am new to programming but here is what I have:
void filesave(void)
{
FILE *fpout;
if(first==(struct account *)NULL)
puts("There are no records to print!");
else
{
if ( (fpout = fopen("test.txt","w+")) == NULL )
{
printf("\n error opening the test.txt file!");
exit(0);
}
current=first;
do
{
/* copy to file */
fprintf (fpout,"%i\n", out->custID);
fprintf (fpout,"%s\n", out->lastname);
fprintf (fpout,"%s\n", out->firstname);
fprintf (fpout,"%s\n", out->street);
fprintf (fpout,"%s\n", out->city);
fprintf (fpout,"%s\n", out->state);
fprintf (fpout,"%s\n", out->zip);
fprintf (fpout,"%s\n", out->rented);
fprintf (fpout,"%f\n", out->balance);
}
while((current=current->next) != (struct account *)NULL);
}
puts("Files Copied!");
system("pause");
fclose(fpout);
return 0;
}
void openrecords(void)
{
FILE *fpin;
if ((fpin = fopen("test.txt","r")) == NULL)
{
printf("\n error opening the test.txt file!");
exit(0);
}
/* a while() statement to find eof */
{
newptr = (struct account *)malloc(sizeof(struct account));
if(first==(struct account *)NULL)
{
first = current = newptr;
current->prior = NULL;
}
else
{
current = first;
while(current->next != (struct account *)NULL)
current = current->next;
last = current;
current->next = newptr; /*save the address of the new record*/
current = newptr;
current->prior = last;
}
fscanf(fpin, "%i", out->custID);
fscanf(fpin, "%s", out->lastname);
fscanf(fpin, "%s", out->firstname);
fscanf(fpin, "%s", out->street);
fscanf(fpin, "%s", out->city);
fscanf(fpin, "%s", out->state);
fscanf(fpin, "%s", out->zip);
fscanf(fpin, "%s", out->rented);
fscanf(fpin, "%f", out->balance);
current->next = (struct account *)NULL;
}
fclose(fpin);
return 0;
}