Home > Electronics Tutorials > C Language Tutorial > string.h - strpbrk

C Language Programming Library Reference Guide

string.h - strpbrk

Declaration: char *strpbrk(const char *str1, const char *str2); Finds the first character in the string str1 that matches any character specified in str2.

A pointer to the location of this character is returned. A null pointer is returned if no character in str2 exists in str1.

Example:

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

int main(void)
{
  char string[]="Hi there, Chip!";
  char *string_ptr;

  while((string_ptr=strpbrk(string," "))!=NULL)
    *string_ptr='-';

  printf("New string is \"%s\".\n",string);
  return 0;
}
The output should result in every space in the string being converted to a dash (-).
Note: To report broken links or to submit your projects, tutorials please email to Webmaster

Discover

     more......