#include <stdio.h>
#define N 3
int num[N];
void inter(int i,char name[][10])
{
printf("inter %d number",i+1);
scanf("%d",&num[i]);
getchar();
printf("inter %d name",i+1);
gets(name[i]);
}
main()
{
int i;char name[N][10];
for (i = 0; i < N; i++)
inter(i,name[i]);
for (i = 0; i < N;i++){
printf("%d\n",num[i]);
getchar();
puts(name[i]);
getch();
}
}
----------------解决方案--------------------------------------------------------
#include <conio.h>
#define N 3
int num[N];
void inter(int i,char name[][10])
{
printf(\"inter %d number\",i+1);
scanf(\"%d\",&num[i]);
getchar();
printf(\"inter %d name\",i+1);
gets(name[i]);
}
void main()
{
int i;
char name[N][10];
for (i = 0; i < N; i++)
inter(i,name);
for (i = 0; i < N;i++)
printf(\"%d %s\n\",num[i],name[i]);
}
----------------解决方案--------------------------------------------------------
#include <stdio.h>
#define N 3
int num[N];
void enter(int i,char name[][10])
{ printf("enter %d number\n",i+1);
scanf("%d",&num[i]);
getchar();
printf("enter %d name\n",i+1);
scanf("%s",name[i]);
}
main()
{
int i;
char name[N][10]={"\0","\0","\0"};
for (i = 0; i < N; i++)
enter(i,name);
for (i = 0; i < N;i++){
{ printf("%d ",num[i]);
printf(" %s\n",name[i]);
} }
getch();
}
好像应该要初始化字符串。
[此贴子已经被作者于2006-11-25 10:09:41编辑过]
----------------解决方案--------------------------------------------------------