我在从文件中获取数字时遇到问题。函数fscanf仅读取字符串。 8

问题描述 投票:-1回答:2

Fscanf不起作用,我不明白为什么。它只读取字符串,而不读取其他内容。1 2 3写入file.txt。这是代码:

include<stdio.h> 

int main() 
{ 
    FILE* ptr = fopen("file.txt","r"); 

    if (ptr==NULL) 
    { 
        printf("no such file."); 
        return 0; 
    } 

    char* buf[100]; 
    int a;

    fscanf(ptr," %d ",a);
        printf("%d\n", a); 
    fscanf(ptr," %s ",buf);

        printf("%s\n", buf); 



    return 0;
}

c input scanf
2个回答
0
投票
    fscanf()的可变参数必须是指针。

0
投票
1。
© www.soinside.com 2019 - 2024. All rights reserved.