免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 6166 | 回复: 5
打印 上一主题 下一主题

一个简单的编译问题,请各位帮看下 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-03-02 10:19 |只看该作者 |倒序浏览
运行C++时总出现错误 ,请问是什么问题

程序名:
test1.C

代码如下:

#include <stdio.h>



void my_print(char *string);

void my_print2(char *string);



main()

{

char my_string[]=”Hello embedded Linux world”;



my_print(my_string);

my_print2(my_string);

}



void my_print(char *string)

{

printf(“The string is &s\n”,string);

}



void my_print2(char *string)

{

char *string2;

int size,i;



size=strlen(string);

string2=(char *)malloc(size+1);

for(i=0;i<size;i++) {

string2[size-i]=string[i];

}

string2[size+1]=’\0’;

printf(“The string printed backward is %s\n”,string2);

}



运行命令:
# g++ -o test1 test1.C

错误如下:
test1.C: In function `int main()':
test1.C:8: stray '\241' in program
test1.C:8: stray '\261' in program
test1.C:8: `Hello' undeclared (first use this function)
test1.C:8: (Each undeclared identifier is reported only once for each function
it appears in.)
test1.C:8: parse error before `Linux'
test1.C:8: stray '\241' in program
test1.C:8: stray '\261' in program
test1.C: In function `void my_print(char*)':
test1.C:16: stray '\241' in program
test1.C:16: stray '\260' in program
test1.C:16: parse error before `is'
test1.C:16: stray '\' in program
test1.C:16: stray '\241' in program
test1.C:16: stray '\261' in program
test1.C: In function `void my_print2(char*)':
test1.C:24: `strlen' undeclared (first use this function)
test1.C:25: `malloc' undeclared (first use this function)
test1.C:29: stray '\241' in program
test1.C:29: stray '\257' in program
test1.C:29: stray '\' in program
test1.C:29: stray '\241' in program
test1.C:29: stray '\257' in program
test1.C:30: stray '\241' in program
test1.C:30: stray '\260' in program
test1.C:30: parse error before `printed'
test1.C:30: stray '\' in program
test1.C:30: stray '\241' in program
test1.C:30: stray '\261' in program
You have new mail in /var/spool/mail/root

论坛徽章:
0
2 [报告]
发表于 2006-03-02 10:24 |只看该作者
C++用#include <stdio.h>?建议用#include <iostream>
从错误信息来看,应该是用了不合适的符号所致。

论坛徽章:
0
3 [报告]
发表于 2006-03-02 10:34 |只看该作者
字串是不是用了全角的引号;
另外把strlen和malloc的头文件加进去

论坛徽章:
0
4 [报告]
发表于 2006-03-02 11:29 |只看该作者
代码是从其他地方复制的么?比如网页上
多了一些无法认出的字符....
原来也碰到过
把出现问题的行的空格删掉重敲试试

论坛徽章:
0
5 [报告]
发表于 2006-03-02 13:06 |只看该作者
谢谢你们的热心帮助:)

论坛徽章:
0
6 [报告]
发表于 2008-06-05 13:29 |只看该作者
该错误是指源程序中有非法字符,需要去掉非法字符。一般是由于从别的地方粘贴过来造成的。

把所粘的文字放到记事本里就行了
http://blog.csdn.net/chris4ting/archive/2007/07/17/1695076.aspx
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP