Register | Sing In

New posts

Stacks in C programming Linked Lists in C programming File Input/Output in C programming Check prime numbers in C Programming C Programming Enumeration C Programming Union

Archives

2013-10 2013-09 2013-08

Function strpbrk in C programming

September 16, 2013 Posted by: GPA Views: 850 0 comments

Problem

Write simple program using function strpbrk() in C programming.

Solution

In this article, you will get example program and explanation about the strpbrk() function of header file <string.h>.

Declaration:

char *strpbrk( const char * firstString , const char * secondString);

This function searches firstString for the first occurrence of any character in secondString. If a character from the second parameter secondString is found, strpbrk returns a pointer to the character in the first parameter; otherwise, strpbrk returns NULL. 

In this example we prompt the user to enter firstString and secondString and then this program searches the first occurrence in firstString of any character from secondString.

Example:



#include <stdio.h>
#include <stdlib.h>
#include <string.h>//include this header file for function strpbrk
//main function
int main(int argc, char *argv[])
{
char firstString[20];//variable for first String
char secondString[20];//variable for second String
printf("globalproganswer.com\n");
printf("Enter first string: ");//promt user to enter some string
gets(firstString);//read string from keyboard
printf("Enter second string: ");//promt user adto enter some string
gets(secondString);//read string from keyboard
char result =*strpbrk(firstString, secondString );//call function strpbrk
if(result!=NULL){//check is result not equal NULL then print
printf("In the second string %s character %c appears in %s",secondString,result,firstString);
}else{
printf("No any character");
}
printf("\n");//new line
system("PAUSE"); //delay
return 0;
}

Output

Function strpbrk

Download this example

0 Comments...

Leave a Reply

Please, Sing In to leave a Reply for this material.



Online Chat

LiveZilla Live Help

Popular posts

Function strtok in C programming Check prime numbers in C Programming C Programming Union Linked Lists in C programming File Input/Output in C programming C Programming Enumeration

RSS-subscribe

New materials

Subscribe