c - 如何接受我的姓名首字母作为输入并在 C 中连同我的姓名一起打印?
问题描述
过去几天,我一直在努力用 C 语言打印我的全名。经过几次尝试,这就是我想出的。
#include <stdio.h>
int main(void)
{
char yourname[20];
int yourage;
char initial;
printf("Whats your name? ");
scanf("%18[^\n]s", yourname);
printf("And your initial is? ");
scanf("%c", &initial);
yourname[19] = '\0';
fflush(stdin);
printf("How old are you? ");
scanf(" %d",&yourage);
printf("Your name is %s %c and you are %i years old.\n", yourname,
initial, yourage);
return(0);
}
当我编译并运行程序时,这就是我得到的。我正在编译时像这样打开了完整的警告
make name
clang -fsanitize=signed-integer-overflow -fsanitize=undefined -ggdb3 -O0 -
std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wshadow name.c -lcrypt -
-lm -o name
请帮忙..
Whats your name? Alokananda
And your initial is? How old are you? 35
Your name is Alokananda
and you are 35 years old.
解决方案
推荐阅读
- java - 我可以将我的原生映像 Java 应用程序打包到一个目录中吗
- c# - 在 Cosmos 中为 MongoDB API 添加复合索引
- mysql - Mysql查询以删除某些类别中的woocommerce产品
- roku - 网速慢时如何管理任务节点的响应?
- c# - 我的播放器没有移动在 Unity 2d 中使用 transform.position
- rust - 如何在函数调用之间在模块内存储状态?
- excel - 将特定工作簿合并为一个
- upgrade - 如何在 Debian 中升级 javac
- python - 从 python3.7 在 bigquery 中插入时间戳值时出错
- r - 是否有任何 R 函数可以从物种分类 ID/物种名称或属名称中提取所有分类名称(门、类、目、科……)?