Keil Logo

strpos

Summary
#include <string.h>

unsigned int strpos (
  const unsigned char *string,   /* string to search */
  char c);                       /* character to find */
Description

The strpos function searches string for the first occurrence of c. The null character terminating string is included in the search.

Return Value

The strpos function returns the index of the character matching c in string or a value of -1 if no matching character was found. The index of the first character in string is 0.

See Also

strchr, strcspn, strpbrk, strrchr, strrpbrk, strrpos, strspn

Example
#include <string.h>
#include <stdio.h> /* for printf */

void tst_strpos (void) {
  unsigned char text [] = "Search this string for blanks";
  unsigned int i;

  i = strpos (text, ' ');

  if (i == -1)
    printf ("No spaces found in %s\n", text);
  else
    printf ("Found a space at offset %d\n", i);
}
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.