C++编程实现:在给定的字符串中查找满足条件的第一个字符。

2024-11-15 19:49:45
推荐回答(1个)
回答(1):

#include
#include
int main(void)
{
char string[17];
char *ptr, c ;
scanf("%c",&c);
strcpy(string, "This is a string");
ptr = strchr(string, c);
if (ptr)
printf("The character %c is at position: %d\n", c, ptr-string);
else
printf("The character was not found\n");
return 0;
}