To Upper C Code Example
Example 1: convert string to uppercase in c For those of you who want to uppercase a string and store it in a variable ( that was what I was looking for when I read these answers ) . # include <stdio.h> //<-- You need this to use printf. # include <string.h> //<-- You need this to use string and strlen() function. # include <ctype.h> //<-- You need this to use toupper() function. int main ( void ) { string s = "I want to cast this" ; //<-- Or you can ask to the user for a string. unsigned long int s_len = strlen ( s ) ; //<-- getting the length of 's'. //Defining an array of the same length as 's' to, temporarily, store the case change. char s_up [ s_len ] ; // Iterate over the source string (i.e. s) and cast the case changing. for ( int a = 0 ; a < s_len ; a ++ ) { // Storing the change: Use the temp array while casting to uppercase. ...