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 );
}