| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 534 人关注过本帖
标题:[求助]指针的困扰
只看楼主 加入收藏
gqchaoyue
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2007-1-20
收藏
 问题点数:0 回复次数:3 
[求助]指针的困扰
#include<stdio.h>
char *strchr(const char *,int letter);
main()
{
char *test="this is the end of the test.";
char (*tempptr)(const char *,int);
char *pointer;
tempptr=strchr;
pointer=tempptr(test,'i');
pointer=strchr(test,'i');
if(*pointer)
{printf("The first of i is at %d\n",pointer-test);
}
else printf("The character is not found.\n");

}
char *strchr(const char *string,int letter)
{ while((*string!=letter)&&(*string))
string++;
return string;
}
这个程序是我在一本书上看到的,在turboC3.0下编译通过,但得不到预期的结果.
后来把 char *test="this is the end of the test.";
改为 char test[]="this is the end of the test.";
就得到正确结果.
怎么会这样呢?各位高手,帮帮忙啊!
搜索更多相关主题的帖子: 指针 困扰 
2007-01-21 10:12
zhufeifei
Rank: 1
等 级:新手上路
威 望:2
帖 子:402
专家分:0
注 册:2006-8-11
收藏
得分:0 
[URL=http://home.]http://home.[/URL]

在不断的拼搏与进取中,定能创造一片天地!
2007-01-21 12:43
gqchaoyue
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2007-1-20
收藏
得分:0 

明白了.谢谢啊!

2007-01-21 14:41
sexqing82
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2007-1-21
收藏
得分:0 

用指针引用字符串 前提指针以指向以存在 并足够的空间

2007-01-21 15:41
快速回复:[求助]指针的困扰
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011908 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved