strncmp
7-52
Example
In the following example, the character strings pointed to by *a, *b, and *c were
assigned the values shown in the comments. In the comments, the notation
\0 represents the null character:
char *a, *b, *c;
size_t size = 13;
.
.
.
/* a−−> ”I do not like them,\0” */;
/* b−−> ” Sam I am, \0” */;
/* c−−> ”I do not like green eggs and ham\0” */;
strncat (a,b,size);
/* a−−> ”I do not like them, Sam I am, \0” */;
/* b−−> ” Sam I am, \0” */;
/* c−−> ”I do not like green eggs and ham\0” */;
strncat (a,c,size);
/* a−−> ”I do not like them, Sam I am, I do not like\0” */;
/* b−−> ” Sam I am, \0” */;
/* c−−> ”I do not like green eggs and ham\0” */;
Compare Strings
strncmp
Syntax
#include <string.h>
int
strncmp
(const char *string1, const char *string2, size_t n);
Defined in
strncmp.c in rts.src
Description
The strncmp function compares up to n characters of string2 with string1. The
function returns 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 not?”;
size_t size = 4;
if (
strncmp(stra, strb, size)
> 0)
{
/* statements here will get executed */
}
if (
strncmp(stra, strc, size)
== 0)
{
/* statements here will get 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...