我想知道是否有办法在fscanf或fgets函数中忽略空格。我的文本文件每行有两个字符,可能用空格分隔,也可能不用。我需要读取这两个字符,并将它们分别放入不同的数组中。
file = fopen(argv[1], "r");
if ((file = fopen(argv[1], "r")) == NULL) {
printf("\nError opening file");
}
while (fscanf(file, "%s", str) != EOF) {
printf("\n%s", str);
vertexArray[i].label = str[0];
dirc[i] = str[1];
i += 1;
}
fscanf(file, " %c %c", &str[0], &str[1])
? - Daniel Fischer