c - 如何克服 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!");
}
}
解决方案
推荐阅读
- python - 如何在有多个输出时修复 ValueError(x 和 y 应该具有相同的长度)?
- visual-studio-code - 如何在 vscode 正则表达式中转义“@”以进行语法突出显示
- javascript - 在反应钩子中,我如何将新创建的对象传递给状态对象?
- php - 将整个 Excel 行复制到表单域中
- html - 文本变换和翻译的翻转坐标系的行为
- visual-studio-code - VSCode 上的 PHP 语言服务器错误:与服务器的连接已关闭。服务器将重新启动。语言服务器以退出代码 255 退出
- apache-kafka - Kafka偏移重置而不重新启动消费者
- typescript - TypeScript:使用属性装饰器时得到错误的对象
- android - 我的 webview 在默认浏览器中打开网页
- python - torch.nn.conv* 中的 groups 参数如何影响卷积过程?