本帖最后由 yes2 于 2023-12-6 16:24 编辑
少了一个大括号
下次编译报错最好把报错信息一起贴上来。[C++] 纯文本查看 复制代码 #include <stdio.h>
#define SIZE 80
char* string_char(char* st, char c);
int main(int argc, char *argv[])
{
char source[SIZE];
char dest = ' ';
char *position;
printf("Enter a String: ");
fgets(source,SIZE, stdin);
while (dest != EOF)
{
printf("Enter a char to find (EOF for Quit):");
while ((dest = getchar()) == '\n')
{
continue;
}
if((position = string_char(source,dest)) != NULL)
{
printf("Found the char %c in the %p\n",*position,position);
}
else
{
printf("Char %c not found.Try another?\n",dest);
}
} // <===少了一个大括号
return 0;
}
char* string_char(char* st, char c)
{
while (*st != '\0')
{
if(*st == c)
{
return st;
}
else
{
st++;
}
}
return NULL;
} |