小编kim*_*ser的帖子

在 C 中使用 fscanf 扫描字符串

请帮我解决一些问题。

该文件包含:

AAAA 111 BBB
CCC 2222 DDDD
EEEEE 33 FF
Run Code Online (Sandbox Code Playgroud)

代码是:

int main() {
    FILE * finput;

    int i, b;
    char a[10];
    char c[10];

    finput = fopen("input.txt", "r");

    for (i = 0; i < 3; i++) {
        fscanf(finput, "%s %i %s\n", &a, &b, &c);
        printf("%s %i %s\n", a, b, c);
    }

    fclose(finput);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

该代码确实有效。但是,会出现以下错误:

format «%s» expects argument of type «char *», but argument 3 has type «char (*)[10]
format «%s» expects argument of type «char *», …
Run Code Online (Sandbox Code Playgroud)

c string file scanf

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

c ×1

file ×1

scanf ×1

string ×1