首页 > 解决方案 > 如何克服 scanf("%[^\n]s",...) 问题

问题描述

直接解决这里的问题,我需要一次扫描一个句子的输入,例如:姓名和姓氏,它不能正常工作尝试像标题中所示的 scanf 和 fgets ,起初它工作正常,但一旦代码是有点复杂,卡住了!我包括一张带有执行代码的图片

*// note this function is called by main(); tried writing the code in the main but the same
#include <stdio.h>
#include <string.h>
#include "Typedefs.h"


User Newuser;
log()
{

    printf("Name & Surname : ");
    fgets(Newuser.FullName,TAILLE_MAX,stdin);
    printf("Age : ");
    scanf("%d",&Newuser.age);
    printf("Matricule : ");
    scanf("%lld",&Newuser.MaT);

    printf("%s %d years \t Matricule : %lld",Newuser.FullName,Newuser.age,Newuser.MaT);
    fichier = fopen("userlog.txt","a+");
    if(fichier != NULL)
    {
        fprintf(fichier,"%s %d years \t Matricule : %lld",Newuser.FullName,Newuser.age,Newuser.MaT);

        fclose(fichier);
    }else
    {
        printf("error opening file!");
    }
}

此链接图像显示正在运行的代码面板

标签: cscanfcodeblocksfgets

解决方案


推荐阅读