I write data from the fields by the save function
int SaveToFile(List* pHead) { FILE *p; p=fopen("C:\\Users\\Elvin\\source\\repos\\LabTree\\LabTree\\savablenoteimeantheuserpressedsss.dat", "wb"); if (p == NULL) return -1; while (pHead) { fprintf(p, "%d ", pHead->Data.time.tm_year); //fprintf(p, "%d ", pHead->Data.time.tm_yday); fprintf(p, "%d ", pHead->Data.time.tm_mon); fprintf(p, "%d ", pHead->Data.time.tm_mday); //fprintf(p, "%d ", pHead->Data.time.tm_wday); fprintf(p, "%d ", pHead->Data.time.tm_hour); fprintf(p, "%d ", pHead->Data.time.tm_min); fprintf(p, "%d ", pHead->Data.importance); //fprintf(p, "%d ", pHead->Data.time.tm_sec); fputs(pHead->Data.description, p); fputs("\n", p); fputs(pHead->Data.whereto, p); fputs("\n", p); pHead = pHead->Next; } fclose(p); return 0; } The reason why I put '\ n' at the end is to stop reading the gets to read correctly into my fields, respectively. I read information from a binary file into the appropriate fields of the structure
while (!feof(p)) { fscanf(p, "%d", &info.time.tm_year); fscanf(p, "%d", &info.time.tm_mon); fscanf(p, "%d", &info.time.tm_mday); fscanf(p, "%d", &info.time.tm_hour); // fscanf(p, "%d", &info.time.tm_hour); fscanf(p, "%d", &info.time.tm_min); fscanf(p, "%d", &info.importance); fgets(info.description, 100, p); fgets(info.whereto, 100, p); int i = 0; info.whereto[strlen(info.whereto)] = '\0'; pnt = push(pnt, info); } However, it seems to me that because of this addition of the character ('\ n'), the function reads the last-remaining value once more and adds it to the stack, and it turns out that there are two identical blocks in the stack. It turns out somewhere moved eof. How to make it so that there is no re-add?
fread, notfgets. But in fact, your file is not binary, but a text one, since you work with it with the help of "text" functions. - insolor