我编写了一些 C 代码,但似乎无法正常工作。我有一个 POST 表单,我希望标记输出(基于 & 限制字符)并将其写入输出文本文件(用逗号分隔数据)。
关于这个编码有什么建议吗?
int main ()
{
static const char Write2File[] = "csvoutput.txt";
FILE *fp = fopen ( Write2File, "w" );
char line[128], str[128];
char *p, *pch;
// while stdin is not null
while ( fgets (line) != NULL )
{
// tokenize the string based on & character
pch = strtok (line,"&");
// writes the token to file
fputs(pch,fp);
// writes a comma to file
fputc(',',fp);
// writes the token to file
fputs(pch,fp);
// takes a new line break
fputc('\n',fp);
}
fclose ( fp );
}