I want to edit the text file so it has more space between successive lines, but there are some weird characters also added at the beginning of the file, which i dont know why.
#include <stdio.h>
#include <string.h>
int main()
{
FILE* fFile;
char str[50], editedContent[500];
if ((fFile = fopen("lab2.txt", "r+")) == NULL)
{
printf("Can not open file for reading.\n");
return 1;
}
while (fgets(str, 50, fFile) != NULL)
{
strcat(editedContent, str);
strcat(editedContent, "\n");
}
//reset position to the beginning of the file and write new content
rewind(fFile);
fputs(editedContent, fFile);
fclose(fFile);
return 0;
}
This is the content of lab2.txt before and after editing: