Hi! Im a newbie here....
I got a problem with my program...My linked list is ok but everytime I export the data to the file, things don't work in a proper way..I will show my code...pls help me...thanks...
labname[20]="lab445.txt";
/****************FWRITE FUNCTION**********************/
void save_data(information *lab,char labname[])
{
FILE *fp;
int num;
char temp[15];
strcpy(temp,labname);
temp[6]='\0';
/* if(lab==NULL)
{ clrscr();
logo();
gotoxy(29,10);printf("%s has an Empty List",temp);
gotoxy(27,14);printf("Press any key to continue..");
} */
if((fp=fopen(labname,"wt"))==NULL)
{ clrscr();
logo();
gotoxy(38,10);printf("Error!");
}
else
{
if(lab==NULL)
putc('\0',fp);
else
{ num=0;
while(lab!=NULL)
{ fwrite(lab,sizeof(information),1,fp);
num++;
lab=lab->next;
}
clrscr();
printf("There are %d copied from the list.",num);
getch();
clrscr();
logo();
for(num=0;num<12;num++)
{ gotoxy(29,10);printf("Saving Data from %s.",temp);
delay(40000);
}
clrscr();
logo();
gotoxy(36,12);printf("Success!!");
gotoxy(27,14);printf("Press any key to continue..");
}
fclose(fp);
}
getch();
}
/********FOR FREAD FUNCTION*****************/
void ret_data(information **lab,char labname[])
{
information *temp;
FILE *fp;
int x=0;
char namelab[20];
clrscr();
if((fp=fopen(labname,"rt"))==NULL)
{ clrscr();
logo();
strcpy(namelab,labname);
namelab[6]='\0';
gotoxy(28,10);printf("NO FILE FOUND in %s",namelab);
gotoxy(28,14);printf("Press any key to continue..");
getch();
}
else
{ while(!feof(fp))
{
temp=(information*)malloc(sizeof(information));
if((fread(temp,sizeof(information),1,fp))!=0)
{
while(*lab!=NULL)
lab=&(*lab)->next;
temp->next=*lab;
*lab=temp;
x++;
}
}
fclose(fp);
clrscr();
printf("There are %d files copied from the file.",x);
getch();
}
}