string.h
You may want to look at the section on arrays
first!. The following macros are built into the file string.h
strcat Appends a string strchr Finds first occurrence of a given character strcmp Compares two strings strcmpi Compares two strings, non-case sensitive strcpy Copies one string to another strlen Finds length of a string strlwr Converts a string to lowercase strncat Appends n characters of string strncmp Compares n characters of two strings strncpy Copies n characters of one string to another strnset Sets n characters of string to a given character strrchr Finds last occurrence of given character in string strrev Reverses string strset Sets all characters of string to a given character strspn Finds first substring from given character set in string strupr Converts string to uppercase To convert a string to uppercase #include <stdio.h> #include <string.h> main() { char name[80]; /* declare an array of characters 0-79 */ printf("Enter in a name in lowercase\n"); scanf( "%s", name ); strupr( name ); printf("The name is uppercase is %s", name ); } Sample Program Output Enter in a name in lowercase samuel The name in uppercase is SAMUEL
BUILT IN FUNCTIONS FOR CHARACTER HANDLING
The following character handling functions are defined in ctype.h
isalnum Tests for alphanumeric character isalpha Tests for alphabetic character isascii Tests for ASCII character iscntrl Tests for control character isdigit Tests for 0 to 9 isgraph Tests for printable character islower Tests for lowercase isprint Tests for printable character ispunct Tests for punctuation character isspace Tests for space character isupper Tests for uppercase character isxdigit Tests for hexadecimal toascii Converts character to ascii code tolower Converts character to lowercase toupper Converts character to uppercase
To convert a string array to uppercase a character at a time using toupper()
#include <stdio.h> #include <ctype.h> main() { char name[80]; int loop; printf("Enter in a name in lowercase\n"); scanf( "%s", name ); for( loop = 0; name[loop] != 0; loop++ ) name[loop] = toupper( name[loop] ); printf("The name is uppercase is %s", name ); } Sample Program Output Enter in a name in lowercase samuel The name in uppercase is SAMUEL