一个c语言的问题

#include <conio.h>
#include <stdio.h>
void countValue(int *a,int *n)
{
int i;
*n=0;
for(i=1;i<=1000;i++)
if((i%7==0&&i%11)||(i%7&&i%11==0))
a[(*n)++]=i;
}
main()
{
int aa[1000],n,k;
system("cls");
countValue(aa,&n);
for(k=0;k<n;k++)
if((k+1)%10==0)printf("\n");
else printf("%5d",aa[k]);
writeDAT();
}
writeDAT()
{
int aa[1000],n,k;
FILE *fp;
fp=fopen("out19.dat","w");
countValue(aa,&n);
for(k=0;k<n;k++)
if((k+1)%10==0) fprintf(fp,"\n");
else fprintf(fp,"%5d",aa[k]);
fprintf(fp,"\n");
fclose(fp);
}--------------------Configuration: fdf - Win32 Debug--------------------
Compiling...
fdf.cpp
c:\users\kent\desktop\ctemp\fdf.cpp(14) : error C2065: 'system' : undeclared identifier
c:\users\kent\desktop\ctemp\fdf.cpp(19) : error C2065: 'writeDAT' : undeclared identifier
c:\users\kent\desktop\ctemp\fdf.cpp(20) : warning C4508: 'main' : function should return a value; 'void' return type assumed
c:\users\kent\desktop\ctemp\fdf.cpp(22) : error C2373: 'writeDAT' : redefinition; different type modifiers
c:\users\kent\desktop\ctemp\fdf.cpp(32) : warning C4508: 'writeDAT' : function should return a value; 'void' return type assumed
执行 cl.exe 时出错.

咋回事

fdf.obj - 1 error(s), 0 warning(s)

第一:system未定义,可能是未引入头文件或者是c语言不支持这个关键字(我以前做的时候没用过这个,不好意思)
第二:函数writeDAT未定义。修改方法:将writeDAT函数放在main之前,或者是在引用头文件之后申明一下,格式为:
#include <conio.h>
#include <stdio.h>
void writeDAT();
....
第三:函数(包括主函数)前应该有其返回值类型,无返回值则为void
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-03-15
system()函数是stdlib.h里的,请#include<stdlib.h>
main函数可定义为int 类型
writeDAT函数定义为void类型,并将其定义或声明放在调用它的地方之前。
#include <conio.h>
#include <stdio.h>
#include<stdlib.h>
void countValue(int *a,int *n)
{
int i;
*n=0;
for(i=1;i<=1000;i++)
if((i%7==0&&i%11)||(i%7&&i%11==0))
a[(*n)++]=i;
}
void writeDAT()
{
int aa[1000],n,k;
FILE *fp;
fp=fopen("out19.dat","w");
countValue(aa,&n);
for(k=0;k<n;k++)
if((k+1)%10==0) fprintf(fp,"\n");
else fprintf(fp,"%5d",aa[k]);
fprintf(fp,"\n");
fclose(fp);
}
int main()
{
int aa[1000],n,k;
system("cls");
countValue(aa,&n);
for(k=0;k<n;k++)
if((k+1)%10==0)printf("\n");
else printf("%5d",aa[k]);
writeDAT();
}
第2个回答  2011-03-16
void writeDAT()
{
int aa[1000],n,k;
FILE *fp;
fp=fopen("out19.dat","w");
countValue(aa,&n);
for(k=0;k<n;k++)
if((k+1)%10==0) fprintf(fp,"\n");
else fprintf(fp,"%5d",aa[k]);
fprintf(fp,"\n");
fclose(fp);
}
只写了其中的某个函数、、
第3个回答  2011-03-16
头文件没加载,函数未定义或者定义的函数返回值类型错
相似回答