我尝试将 char 数组作为名称写入控制台,但它不起作用。这是代码
#include<stdio.h>
#include<string.h>
int F()
{
int S;
printf("Type your student number(10 digit):");
scanf("%d", &S );
return S;
}
char * G()
{
char N[20];
printf("Type your name (max 20 char): ");
scanf("%s", N);
return N;
}
int main()
{
int num=F();
char * p ;
p=G();
printf("Hello %s, your student id is %d ", p,num);
printf("\n The address of 1st char is %x ",&p[0]);
printf("\n The address of 20th char is %x ",&p[19]);
printf("\n The address of int is %x ",&num);
return 0;
}
“你好”之后有问题。名称(*p) 未写入。我找不到任何错误,但输出不是我想要的。