我写了一小段代码,可以从键盘输入地址.但是,我无法弄清楚如何能够读取特殊字符,例如hypen,冒号等.您能否建议对我的代码进行一些编辑:
#include<stdio.h>
main()
{
char address[80];
printf("Enter address: ");
scanf("%[a-z | A-Z | 0-9]", address); //How may I include characters like hypen.
printf("\n\n%s\n\n", address);
}
Run Code Online (Sandbox Code Playgroud)
我得到的输出:
Enter Address: Plot No - 16, Palm Grooves, Nagpur - 440022, India
Plot No
Run Code Online (Sandbox Code Playgroud)
没有逗号,没有连字符,没有显示数字.
感谢您的帮助和评论.
#include<stdio.h>
main()
{
unsigned x=1;
signed char y=-1;
clrscr();
if(x>y)
printf("x>y");
else
printf("x<=y");
}
Run Code Online (Sandbox Code Playgroud)
有符号字符的值从-128增加到127.所以预期的输出应该是'x> y',但事实并非如此.编译器给出输出 - "x <= y".你能解释一下原因吗?