I want to delete the last char of a text file. I have a code that saves strings and I need to delete only the last '\n'.
I already tried to do:
fseek(fp, -1, SEEK_END);
fputs("", fp);
Here's the full code:
void saveGIF(FrameNode** head)
{
FILE* fp = 0;
FrameNode* curr = *head;
int i = 1;
int howManyFrames = framesInList(head);
char c = 0;
char filePath[SIZE] = { 0 };
if (curr == NULL)
{
printf("Nothing to save, add more frames and than save\n");
}
else
{
printf("Where to save the project? enter a full path and file name\n");
getchar();
myFgets(filePath, SIZE);
fp = fopen(filePath, "w+");
if (fp != NULL)
{
while (curr)
{
fprintf(fp, "%s %d %s\n", curr->frame->name, curr->frame->duration, curr->frame->path);
curr = curr->next;
i++;
}
fseek(fp, -1, SEEK_END);
fputs("", fp);
fclose(fp);
}
else
{
printf("Error! canot create file\n");
}
}
}