新手请教,请求改正程序错误[02]!
新手请教,请求改正程序错误[02]!
初次接触Visual C++ 6.0,以下是考试例题,但编译出错,请帮忙修改!
//题目
编写一个函数fun(str),它的功能是:统计由实参传来的一个字符串中的字母,数字,空格和其它字符号个数,
部分源程序给出如下,请勿改动主函数main和其它函数中的任何内容,
仅在函数fun的花括号中填入你编写的若干语句.
程序版本:Visual C++ 6.0
程序代码如下:
#include "stdafx.h"
int alph,digit,space,others;
void main()
{
char text[80];
printf("\nEnter a string:");
gets(text);
printf("it is:");
puts(text);
alph=digit=space=others=0;
fun(text);
printf("\n alph=%d,digit=%d,space=%d,others=%d\n",alph,digit,space,others);
}
fun(str)
char str[];
{int i,temp;
for(i=0;str[i]!='\0';i++)
{temp=str[i];
if(isalpha(str[i])) alph++;
else if(isdigit(temp)) digit++;
else if(isspace(temp)) space++;
else others++;}
return alph,digit,space,others;
}
以下是编译出错信息!
-------------------Configuration: chapter7 - Win32 Debug--------------------
Compiling...
chapter7.cpp
E:\xuexi\vc++\example\chapter7\chapter7.cpp(14) : error C2065: 'fun' : undeclared identifier
E:\xuexi\vc++\example\chapter7\chapter7.cpp(18) : error C2065: 'str' : undeclared identifier
E:\xuexi\vc++\example\chapter7\chapter7.cpp(19) : error C2448: '<Unknown>' : function-style initializer appears to be a function definition
E:\xuexi\vc++\example\chapter7\chapter7.cpp(19) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.
chapter7.exe - 1 error(s), 0 warning(s)