Write a program to search a character in a string using pointer in C language.

 

 C PROGRAM





#include<stdio.h>
#define SIZE 50
int main()
{
    char input[SIZE];
    char *p,c;
    int flag = 0;
    printf("\nEnter any String : ");
    fgets(input,SIZE,stdin);
    printf("\nEnter a character you want to find in string: ");
    scanf("%c",&c);
    p = input;
    while(*p != '\0')
    {
        if (*p == c)
        {
            flag = 1;
            break;
        }
    p++;
    }
    if (flag == 1)
    {
        printf("\n<-- Character you entered is FOUND in given string.-->");
    }
    else
    {
        printf("\n<-- Character you entered is NOT FOUND in given string.-->");
    }
    return 0;
}


INPUT && OUTPUT








Post a Comment

0 Comments