Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Homework HelpRSS Feeds

FUNCTION XSTRCHR() WHICH SCANS A STRING FROM START TO END IN SEARCH OF A CHARACTER

Posted By: Millie Brown     Category: C Programming     Views: 2553

WRITE A FUNCTION XSTRCHR() WHICH SCANS A STRING FROM START TO END IN SEARCH OF A CHARACTER. IF THE CHARACTER
IS FOUND THEN RETURN IT'S POINTER WITH ITS ADDRESS AND
IF NOT FOUND THEN RETURN NULL VALUE.

Code for FUNCTION XSTRCHR() WHICH SCANS A STRING FROM START TO END IN SEARCH OF A CHARACTER in C Programming

#include <stdio.h>
#include <conio.h>

main()
{
    char *a1,*a2,ch;
    char * xstrchr(char *,char);
    clrscr();
    fflush(stdin);
    printf("ENTER THE STRING:->");
    scanf("%[^\n]s",a1);
    fflush(stdin);
    printf("\nENTER THE CHARACTER WHICH YOU WANT TO SEEK:->");
    scanf("%c",&ch);
    a2=xstrchr(a1,ch);
    if (a2==NULL)
        printf("THE CHARACTER %c IS NOT FOUND IN THE STRING.",ch);
    else
        printf("THE CHARACTER %c FOUND AT ADDRESS %u",ch,a2);
    getch();

}

char * xstrchr(char *str,char ch)
{
    int i=0;
    while(str[i]!='\0')
    {
        if(str[i]==ch)
            return(&str[i]);
        i++;
    }
    return NULL;

}
  
Share: 



Millie Brown
Millie Brown author of FUNCTION XSTRCHR() WHICH SCANS A STRING FROM START TO END IN SEARCH OF A CHARACTER is from London, United Kingdom.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!