strchr.c

来自「c21Examples.rar」· C语言 代码 · 共 30 行

C
30
字号
/* Searching for a single character with strchr(). */

#include <stdio.h>
#include <string.h>

int main( void )
{
    char *loc, buf[80];
    int ch;

    /* Input the string and the character. */

    printf("Enter the string to be searched: ");
    gets(buf);
    printf("Enter the character to search for: ");
    ch = getchar();

    /* Perform the search. */

    loc = strchr(buf, ch);

    if ( loc == NULL )
        printf("The character %c was not found.", ch);
    else
        printf("The character %c was found at position %d.\n",
                ch, loc-buf);
    return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?