[求助]指针的困扰
#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.";
就得到正确结果.
怎么会这样呢?各位高手,帮帮忙啊!