我目前正在学习 C 编程,并且遇到了这个奇怪的输出。
// Program will try functionalities of the scanf function
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char const *argv[])
{
char array[40];
scanf("Enter your address: %39s",array); //39 + 1/o null character at the end of the character array.
printf("The address is : %s", array);
return 0;
}
它应该接受输入地址并输出相同的地址。
PS C:\Users\G\Documents\C programs> gcc scanff.c -o scanff -Wall -pedantic -std=c99
PS C:\Users\G\Documents\C programs> ./scanff
jhgjhg
The address is : ■ a
那个黑块是什么?有人可以解释一下吗!
谢谢。
只需正确使用格式说明符即可scanf()
函数并使用显示自定义消息printf()
.
看一下下面的代码:
// Program will try functionalities of the scanf function
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char const *argv[])
{
char array[40];
printf("Enter your address: ");
scanf("%39s",array); //39 + 1/o null character at the end of the character array.
printf("The address is : %s", array);
return 0;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)