I’m trying to make my own function that takes a sentence and turns every letter in it into an uppercase. I know there’s a pre-defined function that does this but i’m trying to make own myself. Here’s what I have so far. If I just knew how to take every value of ‘p’ and line them in order as a string id be golden. Thanks
int p;
char x ;
void setup ()
{
String str = "I am Happy to See You.";
String capstr = All_uppercase (str);
println(capstr);
}
String All_uppercase(String a)
{
char x;
for(int i = 0 ; i < a.length(); i ++)
{
int p ;
if(a.charAt(i) > 96)
{
p = a.charAt(i) - 32;
}
else
{
p = a.charAt(i);
}
x = (char(p));
}
String word =
return word;
}
// Start the ALL_UPPERCASE function, taking in an input string.
// Have a character, x, that will store the result of converting a single letter to uppercase
// Have a String, output, that will contain all the letters the loop has processed so far.
// Initially, this output string is the empty string, "".
// Loop over every letter in the input string. For each letter,
// If the letter is a lowercase letter,
// make character x be the uppercase version of it.
// otherwise,
// Make x be that letter.
// End of conditional statement. the variable x is the next character to add at this point.
// Next, append the character x to the output string.
// Maybe print the output string here so you can see the progress.
// End of looping over every character in the input string.
// Return the output string.
// End of function
Do you understand the process? Can you now write the line of code for each step?