これが私がやろうとしていることです。
情報を含むファイルがあります。すべての行の前に、行番号が表示されるように書き直そうとしています。
私が念頭に置いている基本的な考え方は、次のように機能します。
while i haven't reached the end of the file:
save the first line of the file (100 characters or until null is reached) in str
go back to the file, and write "line number" and then the info in str.
now str takes the next 100 chars...rinse and repeat.
実際のコード:
void add_line_number(FILE* f1)
{
char str[100];
int i=1;
fseek(f1,0,SEEK_SET);
do
{
fgets(str,100,f1);
fprintf(f1,"%d %s",i,str);
i++;
f1+=strlen(str);
}while(strlen(str));
}
エラーの取得: エッセイ 4.exe の 0x77e78dc9 で未処理の例外: 0xC0000005: アクセス違反の書き込み場所 0xfffff204.