بســم الله الـرحمــن الرحيــم
عندي مشكلة عند حفظ linked list في ملف وهو عند القراءة مرة اخرى .. يكرر اول node مرتين وهذا هو الكود بلغة السي
int WriteFile(struct Book1 data)
{
int x=0;
FILE *fptr;
fptr=fopen("Phonebook1.txt","w+");
if(fptr==NULL)
{
printf("stderr","cannot open the file");
x=1;
}
else
{
x= fwrite(&data,sizeof(data),1,fptr);
fclose(fptr);
}
return x;
}
////read from file////////
void ReadFile(void)
{
struct Book1 data;
FILE *fptr;
int x;
fptr=fopen("PhoneBook1.txt","r");
if(fptr != NULL)
{
fseek(fptr, 0L, SEEK_SET);
do{
x= fread(&data,sizeof(data),1,fptr);
if(x==1)
{
add_Node(data);
}
}
while(!feof(fptr));
//////assuming that data is sorted
}
fclose(fptr);
}