[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]


strcspn

Find the first character in one string that is in another.

Compatibility:

This function is compatible with the following targets:

ANSI

BeOS

EMB/RTOS

Mac OS

Palm OS

Win32


Prototype:
#include <string.h>
size_t strcspn(const char *s1, const char *s2);
Parameters:

Parameters for this facility are:

s1  
const char *  
The string to count  
s2  
const char *  
The list string of character to search for  

Remarks:

The strcspn() function finds the first character in the null terminated character string s1 that is also in the null terminated string s2. For this purpose, the null terminators are considered part of the strings. The function starts examining characters at the beginning of s1 and continues searching until a character in s1 matches a character in s2.

Return:

strcspn() returns the index of the first character in s1 that matches a character in s2.

See Also:

"strpbrk"

"strspn"

Example of strcspn() usage.:
#include <string.h>
#include <stdio.h>

int main(void)
{
	static char s1[] = "chocolate *cinnamon* 2 ginger";
	static char s2[] = "1234*";
	int i;

	printf(" s1 = %s\n s2 = %s\n", s1, s2);
	i = strcspn(s1, s2);
	printf("Index returned by strcspn %d\n", i);
	printf("Indexed character  = %c\n", s1[i]);

	return 0;
}

Output:
s1 = chocolate *cinnamon* 2 ginger
s2 = 1234*
Indexed character  = *


[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.

Last updated: August 16, 2000