0
我想重複追加一個文件行到一個叫做行的字符串。我的代碼工作正常時,我只是嘗試打印行,但因爲我必須解析信息,我需要存儲它。如何重複將文本追加到C中的字符串?
int main(int argc, char *argv[])
{
// Check for arguments and file pointer omitted
FILE *f = fopen(argv[1], "r");
char *times;
int i = 0;
for (i = 0; i < 2000; i++)
{
char line[80];
if (fgets(line, 80, f) == NULL)
break;
//I want every line with the text "</time> to be added to string times
if(strstr(line, "</time>"))
{
times = strcat(times, line); //This line is my problem
}
}
printf(times);
fclose(f);
return 0;
}
您是否閱讀過[strcat](http://linux.die.net/man/3/strcat)的文檔? _「目標字符串必須有足夠的結果空間」_ –
並且必須也是'nul'端口。 –