Después de de esta extensa compilación de datos dimos con la solución este enigma que pueden tener muchos lectores. Te ofrecemos la solución y esperamos que te sea de gran ayuda.
Ejemplo 1: convertir string a mayúsculas en 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 //<-- You need this to use printf.#include //<-- You need this to use string and strlen() function.#include //<-- You need this to use toupper() function.intmain(void)
string s ="I want to cast this";//<-- Or you can ask to the user for a string.unsignedlongint 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.
s_up[a]=toupper(s[a]);// Assign the new array to your first variable name if you want to use the same as at the beginning
s = s_up;printf("%s n", s_up);//<-- If you want to see the change made.//If you want to lowercase a string instead, change toupper(s[a]) to tolower(s[a]).
Ejemplo 2: programación toupper c
inttoupper(int arg );
Ejemplo 3: convertir string a minúsculas en c
// include all the libraries used in the program.#include #include #include #include #include // Base Functionintmain(int argc, string argv[])if(argc !=2)printf("Usage: ./substitution keyn");elseif(strlen(argv[1])!=26)printf("Key must contain 26 characters.n");
string key = argv[1].toupper();
string key = argv[1].tolower();
Comentarios y puntuaciones
Acuérdate de que te damos el privilegio agregar una reseña si diste con la solución.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)