I have this function which saves in a text file the friends of each student. The names of students were saved in a different text files and the code for that is working fine, so i did not include it. However, when I view my friends.txt, I noticed that there's an extra "white space" below the supposedly end of the file. How do I remove this?
void save(student *h, student *t){
FILE *fp1;
student *y = h->next;
fp1 = fopen("friends.txt", "w");
while(y != t){
friend *y1 = y->friendh->next;
if(y1 != y->friendt){
while(y1 != y->friendt->prev){
fprintf(fp1, "%s ", y1->friends);
y1 = y1->next;
}
if(y1 == y->friendt->prev){
fprintf(fp1, "%s\n", y1->friends);
}
}
y = y->next;
}
fclose(fp1);
}