Function | Description
|
strlen | Get the length of the string |
strcat | Append to a string |
strcpy | Copy into a string |
strupr | Convert all characters to uppercase |
strlwr | Convert all characters to lowercase |
strcmp | Compare two strings lexicographically |
#include <string.h> // for all string functions
#include <iostream.h> // for input/output
void main(void)
{
char string1[20];
char string2[20] = "Hello";
int len, diff;
strcpy(string1, "Celsius"); // string1 "Celsius"
len = strlen("Celsius"); // len = 7
len = strlen(string1); // len = 7
strcat(string1, " Temp"); // string1 += " Temp"
len = strlen(string1); // len = 12
strupr(string1); // string1 = "CELSIUS TEMP"
strlwr(string1); // string1 = "celsius temp"
diff = strcmp(string1, string2); // compare
if (diff == 0)
cout << "The strings are the same";
else if (diff < 0)
cout << "string1 comes BEFORE string2";
else
cout << "string1 comes AFTER string2";
}