我正在创建一个C程序,它读取一个CSV文件行的署名。所以每一行都是这样分配的:
sch = strtok (line,",");
第一个标记(而且只需要一个)是表单中的日期时间戳:
2013-12-13 09:15:00.000
然后,我如何使用空格将这个令牌拆分成只存储令牌的时间段?
感谢您的帮助-我已经更新了此处的代码以反映以下建议的更改,但当您尝试执行时,我的程序崩溃:
while ( fgets (line, 512, file) != NULL )
{
sch = strtok (line,",");
if (sch != NULL)
{
sch = strtok (line," ");
sch = strtok (NULL," ");
fputs(sch,filetwo);
fputc('\n',filetwo);
break;
}
sch = strtok (NULL, ",");
}
最佳答案
然后,您将再次致电strtok
。见下文,
while ( fgets (line, 512, file) != NULL )
{
char * tmp = strtok (line,",");
if (tmp != NULL)
{
sch = strtok (tmp," ");
sch = strtok (NULL," ");
fputs(sch,filetwo);
fputc('\n',filetwo);
}
}