这就是我想要做的,未处理的异常,将信息写入文件C语言
我有一个带有信息的文件。我试图在每行之前重写它,行号会出现。
的基本想法,我心目中是这样工作的:
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));
}
得到的错误:未处理的异常在0x77e78dc9征文4.exe:0000005:访问冲突写位置0xfffff204。
我试过了。我进入一个无限循环,因为海峡始终以相同的字符串(从f1到下一个\ 0,因为F1是恒定的,所以是STR) – 2013-05-13 19:59:04
此外,在同一圈上的同一个文件*做fprintf中作为与fgets是不是一个好主意。 – edtheprogrammerguy 2013-05-13 20:09:14