C代码问题........帮助! [英] Problem with C code........ HELP!
本文介绍了C代码问题........帮助!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在用C开发一个简单的程序,
但我遇到了一个问题:
我的代码:
I am developing a simple program in C,
but I encountered a problem :
My Code :
#include<stdio.h>
int main()
{
int menuinpt;
printf("Welcome to C game!!!!\n");
printf("1. Play Game\n");
read:
printf("Enter a Command to start : ");
scanf("%d", &menuinpt);
if (menuinpt != 1)
{
goto read;
}
if (menuinpt == 1)
{
char * name;
printf("Hello Dude! Looks like you are gonna play this games\n");
printf("I am Richard your guide of this game.\n");
printf("Now you gotta tell me your name\n>");
scanf("%d", &name);
printf("Okay your name is %d", name);
getchar();
}
}
我正在使用GCC(代码:Blocks)来编译它,但每当我输入Sid时它就说:
I am using GCC(Code:Blocks) to compile this but whenever I enter "Sid" it says :
Your Name is 48
而不是你的名字是Sid
如何解决这个问题?
任何帮助都会受到赞赏......
~Sids123
instead of "Your Name is Sid"
How can I solve this?
Any help would be appreciated......
~Sids123
推荐答案
你使用了错误的格式代码%d(扫描一个整数作为带符号的十进制数)它应该是%s(扫描一个字符串)。
阅读此处了解更多信息: http://en.wikipedia.org/wiki/Scanf_format_string [ ^ ]
问候,
- Manfred
You're using the wrong format code %d (Scan an integer as a signed decimal number) it should be %s (Scan a character string).
Read here to learn more: http://en.wikipedia.org/wiki/Scanf_format_string[^]
Regards,
— Manfred
这篇关于C代码问题........帮助!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文