关于指针有个小疑问?
#include <stdio.h>
#include <string.h>
#define LEN 100
#define LIMIT 2
char *find_char(char, char *);
int main(void)
{
char c;
char line_w[LEN];
char *p;
printf("你有%d次的测试机会\n", LIMIT);
for(int i = 1; i <= LIMIT; i++)
{
printf("请输入一个字符:");
c = getchar();
while(getchar() != '\n')continue;
printf("请输入一行:\n");
gets(line_w);
p = find_char(c, line_w);
printf("该字符的地址为:%p\n", p);
printf("使用函数strchr的结果为:%p\n", strchr(line_w, c));
}
return 0;
}
char *find_char(char c, char *source)
{
while(*source)
{
if(c == *source)
{
return source;
}
source++;
}
}