C 为什么我的函数不能接受用户输入?

C 为什么我的函数不能接受用户输入?,c,io,scanf,C,Io,Scanf,该代码应该为患者数据获取用户输入,并将其保存在一个文件中,该文件应在以后访问,但scanf功能不起作用 你知道这里可能有什么问题吗?你的scanf格式不正确,应该是: void patient_data(){ char name[10]; int ID[4]; int age; char history[100]; float temp; int breath; printf("enter patient data:\n");

该代码应该为患者数据获取用户输入,并将其保存在一个文件中,该文件应在以后访问,但scanf功能不起作用

你知道这里可能有什么问题吗?

你的scanf格式不正确,应该是:

void patient_data(){    

    char name[10];
    int ID[4];
    int age;
    char history[100];
    float temp;
    int breath; 

    printf("enter patient data:\n");    

    scanf("name : %s\n", name);
    scanf("ID: %d\n",ID);
    scanf("age %d\n",&age);
    scanf("history: %s\n", history);
    scanf("temp: %f\n",&temp);
    scanf("breath: %s\n", breath);

    FILE *info;
    info = fopen("info.txt","a");   

    fscanf(info,"%s     %d  %d  %s  %f  %d",name, ID, &age, history, &temp,&breath);
}
您的scanf格式不正确,应该是:

void patient_data(){    

    char name[10];
    int ID[4];
    int age;
    char history[100];
    float temp;
    int breath; 

    printf("enter patient data:\n");    

    scanf("name : %s\n", name);
    scanf("ID: %d\n",ID);
    scanf("age %d\n",&age);
    scanf("history: %s\n", history);
    scanf("temp: %f\n",&temp);
    scanf("breath: %s\n", breath);

    FILE *info;
    info = fopen("info.txt","a");   

    fscanf(info,"%s     %d  %d  %s  %f  %d",name, ID, &age, history, &temp,&breath);
}

…不工作,请详细说明。这将从文件中读取数据,而不是从用户输入中读取数据。如果您想获取用户输入,然后将其保存到文件中,您可以从用户处扫描它,然后将其打印到文件中。您可以打开信息进行写入,然后使用读取功能fscanf…不起作用。请详细说明。这将从文件中读取数据,而不是从用户输入中读取数据。如果您想获取用户输入,然后将其保存到文件中,您可以从用户处扫描它,然后将其打印到文件中。您可以打开信息进行写入,然后使用读取函数fscanf
fprintf(info,"%s     %d  %d  %s  %f  %d", name, ID, age, history, temp, breath);