主题:难道是指针赋值问题,见源码!
[code=c]
#include <stdio.h>
#include <string.h>
#define MAX 100
char *cstrchr(const char * ,char );
int main(void)
{
char ch;
char text[MAX]="this is a test";
char *found;
printf("input a char for search\n");
scanf("%c",ch);
found=cstrchr(text,ch);
puts(found);
}
char *cstrchr(const char *str, char c)
{
char *find;
while (*find=*str)
{
if(*find==c)
return find;
find++;str++;
}
return NULL;
}
[/code]
上面的程序编译通过,可是运行不了,敢问哪出问题了,谢谢
#include <stdio.h>
#include <string.h>
#define MAX 100
char *cstrchr(const char * ,char );
int main(void)
{
char ch;
char text[MAX]="this is a test";
char *found;
printf("input a char for search\n");
scanf("%c",ch);
found=cstrchr(text,ch);
puts(found);
}
char *cstrchr(const char *str, char c)
{
char *find;
while (*find=*str)
{
if(*find==c)
return find;
find++;str++;
}
return NULL;
}
[/code]
上面的程序编译通过,可是运行不了,敢问哪出问题了,谢谢