Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 将文件读入正确的“问题”;格式";使用strtok_C - Fatal编程技术网

C 将文件读入正确的“问题”;格式";使用strtok

C 将文件读入正确的“问题”;格式";使用strtok,c,C,我在使用strtok读取具有特定格式的文件时遇到问题。 文件中的每一行都包含如下所示的格式: 比尔·辛普森,01452356 当我仅显示temp\u id时,我得到(下划线=空白): 每行代码如下所示: while((fgets(temp_string, LENGTH, ifp))!= NULL) { temp_name = strtok(temp_string, comma); temp_id = strtok(NULL, comma);

我在使用strtok读取具有特定格式的文件时遇到问题。 文件中的每一行都包含如下所示的格式:

比尔·辛普森,01452356

当我仅显示
temp\u id
时,我得到(下划线=空白):

每行代码如下所示:

while((fgets(temp_string, LENGTH, ifp))!= NULL)
    {
          temp_name = strtok(temp_string, comma);
          temp_id = strtok(NULL, comma);
          add(temp_name, temp_id);
    }
我只想
temp\u id
不包含空格。 请记住,
temp\u name
temp\u id
都是char类型的数组。
如果能迅速解决这个问题,我将不胜感激

您需要明确地包含
空格
字符作为分隔符

char comma[] = ", ";
他们可能是另一种情况

char comma[] = " ,";
因为它们不是一个序列,而是一组可能是分隔符的字符。

的可能重复项
char comma[] = " ,";