主题:[讨论]这个是什么问题?
#include<stdio.h>
void main()
{
int pn;
void input(char name[][30],int num[]);
scanf("%d",&pn);
input(name,num);
}
void input(char name[pn][30],int num[pn])
{
int i;
for(i=0;i<pn;i++)
{
printf("\n%d.Name:",i+1);
gets(name[i]);
printf("Number:");
scanf("%d",&num[i]);
}
}
运行结果:
--------------------Configuration: c - Win32 Debug--------------------
Compiling...
c.c
G:\Learning Files\C语言\a\c.c(7) : error C2065: 'name' : undeclared identifier
G:\Learning Files\C语言\a\c.c(7) : warning C4047: 'function' : 'char (*)[30]' differs in levels of indirection from 'int '
G:\Learning Files\C语言\a\c.c(7) : warning C4024: 'input' : different types for formal and actual parameter 1
G:\Learning Files\C语言\a\c.c(7) : error C2065: 'num' : undeclared identifier
G:\Learning Files\C语言\a\c.c(7) : warning C4047: 'function' : 'int *' differs in levels of indirection from 'int '
G:\Learning Files\C语言\a\c.c(7) : warning C4024: 'input' : different types for formal and actual parameter 2
G:\Learning Files\C语言\a\c.c(10) : error C2065: 'pn' : undeclared identifier
G:\Learning Files\C语言\a\c.c(10) : error C2057: expected constant expression
G:\Learning Files\C语言\a\c.c(10) : error C2466: cannot allocate an array of constant size 0
G:\Learning Files\C语言\a\c.c(10) : error C2057: expected constant expression
G:\Learning Files\C语言\a\c.c(10) : error C2466: cannot allocate an array of constant size 0
执行 cl.exe 时出错.
c.exe - 1 error(s), 0 warning(s)
PS:这是我自己简化出来的程序部分,是哪里出问题呢?应该怎么改呢?
void main()
{
int pn;
void input(char name[][30],int num[]);
scanf("%d",&pn);
input(name,num);
}
void input(char name[pn][30],int num[pn])
{
int i;
for(i=0;i<pn;i++)
{
printf("\n%d.Name:",i+1);
gets(name[i]);
printf("Number:");
scanf("%d",&num[i]);
}
}
运行结果:
--------------------Configuration: c - Win32 Debug--------------------
Compiling...
c.c
G:\Learning Files\C语言\a\c.c(7) : error C2065: 'name' : undeclared identifier
G:\Learning Files\C语言\a\c.c(7) : warning C4047: 'function' : 'char (*)[30]' differs in levels of indirection from 'int '
G:\Learning Files\C语言\a\c.c(7) : warning C4024: 'input' : different types for formal and actual parameter 1
G:\Learning Files\C语言\a\c.c(7) : error C2065: 'num' : undeclared identifier
G:\Learning Files\C语言\a\c.c(7) : warning C4047: 'function' : 'int *' differs in levels of indirection from 'int '
G:\Learning Files\C语言\a\c.c(7) : warning C4024: 'input' : different types for formal and actual parameter 2
G:\Learning Files\C语言\a\c.c(10) : error C2065: 'pn' : undeclared identifier
G:\Learning Files\C语言\a\c.c(10) : error C2057: expected constant expression
G:\Learning Files\C语言\a\c.c(10) : error C2466: cannot allocate an array of constant size 0
G:\Learning Files\C语言\a\c.c(10) : error C2057: expected constant expression
G:\Learning Files\C语言\a\c.c(10) : error C2466: cannot allocate an array of constant size 0
执行 cl.exe 时出错.
c.exe - 1 error(s), 0 warning(s)
PS:这是我自己简化出来的程序部分,是哪里出问题呢?应该怎么改呢?