求助高手指点gcc编译问题?

[复制链接]
查看11 | 回复1 | 2007-7-4 17:27:50 | 显示全部楼层 |阅读模式
本人在red hat9.0环境下编写了一个测试程序test.c,内容如下:
#include
main()
{
char ssss[250];
charemp_no[9],emp_name[31];
int i;
strcpy(emp_no,"001&quot

;
strcpy(emp_name,"新昊&quot

;
i=computer_len(emp_no,emp_name);
fprintf(stdout,"员工号=%-15s 姓名=%-15s (%d)\n",emp_no,emp_name,i);
}
intcomputer_len(tmp1,tmp2)
char tmp1[9],tmp2[31];
{
return strlen(tmp1) + strlen(tmp2);
}
以上程序使用gcc编译,一切正常,使用g++编译:
g++ test.c -o test
则系统提示如下出错信息,如何解决?
testora.c: In function `int main()':
testora.c:386: `computer_len' undeclared (first use this function)
testora.c:386: (Each undeclared identifier is reported only once for each
function it appears in.)
testora.c: At global scope:
testora.c:451: `tmp1' was not declared in this scope
testora.c:451: `tmp2' was not declared in this scope
testora.c:452: `int computer_len' used prior to declaration
testora.c:452: initializer list being treated as compound expression
testora.c:452: syntax error before `char'
make[1]: *** [cppbuild] Error 1
make[1]: Leaving directory `/home/deposit/src/proc'
make: *** [testora] Error 2
回复

使用道具 举报

千问 | 2007-7-4 17:27:50 | 显示全部楼层
g++是用来编译C++代码的, 正确如下:
#include
#include
#include
int computer_len(char *tmp1,char *tmp2);
int main()
{
char emp_no[9], emp_name[31];
int i;
strcpy(emp_no,"001&quot

;
strcpy(emp_name,"新昊&quot

;
i=computer_len(emp_no,emp_name);
fprintf(stdout,"员工号=%-15s 姓名=%-15s (%d)\n",emp_no,emp_name,i);
return 0;
}
int computer_len(char *tmp1,char *tmp2)
{
return strlen(tmp1) + strlen(tmp2);
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行