我是C编程新手,我不知道我能在这段代码中改变什么,如果我编译这段代码,它只显示n次的姓氏。为什么它不会显示其他名称,请帮助专家。谢谢!如何使用for循环打印输入的字符串?
#include<stdio.h>
#include<string.h>
#include<malloc.h>
int main()
{
int a;
char n[50];
printf("enter the number of students:\n");
scanf("%d",&a);
printf("enter the names of the students\n");
int i;
for(i=0;i<a;i++)
{
scanf("%s",n);
}
for(i=0;i<a;i++)
{
printf("%s\n",n);
}
return 0;
}
移动打印到第一循环? –