我正在学习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
那个黑色的块是什么?有人能解释一下吗!谢谢。
array
indicates base address, so use either%u
or%p
asprintf("%u", array);
usage ofscanf
is wrong use asscanf("%s",array);
- csavvy