Topics
• String Libraries
• String Operations
• Sample Program
Reading
• Sections 8.1 - 8.7
• String assignment:
strcpy( destination, source )
#include files:
#include <stdlib.h>
/* needed by atoi( ) and atof( ) */
#include <string.h>
/* needed by str...( ) functions */
#include <stdio.h>
#include <stdlib.h> /* needed by atoi( ) and
atof( ) */
#include <string.h> /* needed by str...( )
functions */
printf( "\n=============\n");
printf( "string a = %s string c = %s\n", a, c );
/* "Excellence" comes before "Failure", so print a
negative number */
printf( "strcmp( a, c ) gives %d\n", strcmp( a, c ) );
return 0;
}
=============
String b = >Excellence< and is 10 characters long
After strcat(b, " "), string b = >Excellence < and is 11
characters long
After strcat(b, a), string b = >Excellence
Excellence< and is 21 characters long
strtok( b, " " ) gives Excellence
=============
string a = Excellence string c = Failure
strcmp( a, c ) gives -1
strcmp( c, a ) gives 1
strcmp( a, "Excellence" gives 0
After strcmp( "CMSC", "IFSM" ), result is -1
After strcmp( "IFSM", "CMSC" ), result is 1
After strcmp( "CMSC", "CMSC" ), result is 0
=============
atoi( "1234" gives 1234
atof( "1234.5678" ) gives 1234.567800