strchr
7-48
Find First Occurrence of a Character
strchr
Syntax
#include <string.h>
char *
strchr
(const char *string, char c);
Defined in
strchr.c in rts.src
Description
The strchr function finds the first occurrence of c in string. If strchr finds the
character, it returns a pointer to the character; otherwise, it returns a null point-
er (0). The strchr function is expanded inline when the
−
x option is used.
Example
char *a = ”When zz comes home, the search is on for z’s.”;
char *b;
char the_z = ’z’;
b = strchr(a,the_z);
After this example, b points to the first z in zz.
String Compare
strcmp/strcoll
Syntax
#include <string.h>
int
strcoll
(const char *string1, const char *string2);
int
strcmp
(const char *string1, const char *string2);
Defined in
strcmp.c in rts.src
Description
The strcmp and strcoll functions compare string2 with string1. The functions
are equivalent; both are supported to provide compatibility with ANSI C. The
strcmp function is expanded inline when the
−
x option is used.
The functions return one of the following values:
< 0
if *string1 is less than *string2
0
if *string1 is equal to *string2
> 0
if *string1 is greater than *string2
Example
char *stra = ”why ask why”;
char *strb = ”just do it”;
char *strc = ”why ask why”;
if (
strcmp(stra, strb)
> 0)
{
/* statements here will be executed */
}
if (
strcoll(stra, strc)
== 0)
{
/* statements here will be executed also */
}
Summary of Contents for TMS320C2x
Page 8: ...viii...
Page 69: ...2 47 C Compiler Description...
Page 159: ...6 36...
Page 226: ...8 6...