I need help in debugging this program. The original question is ->Write a function void ConvertUpper(char S[], int n) which will convert all letters in the array to upper case. For example, ConverUpper(S, 7) using the array S defined (S[7] = {'C', 'o', 'M', 'p', 'r', 'O', '2'};) will result into a modified array S containing ’C’, ’O’, ’M’, ’P’, ’R’, ’O’, ’2’. We cant use toupper function. void ConvertUpper(char S[], int n) { int i; for (i = 0; i < n; i++) { /* if the characters are in lower case, convert them to upper case by subtracting 32 from their ASCII value. */ if(S[i] >= 'a' && S[i] <= 'z') { S[i] = S[i] -32; } printf("\n uppercase letters: %c",S); } } int main() { char S[7] = {'C', 'o', 'M', 'p', 'r', 'O', '2'}; ConvertUpper(S,7); }
I need help in debugging this program. The original question is ->Write a function void ConvertUpper(char S[], int n) which will convert all letters in the array to upper case. For example, ConverUpper(S, 7) using the array S defined (S[7] = {'C', 'o', 'M', 'p', 'r', 'O', '2'};) will result into a modified array S containing ’C’, ’O’, ’M’, ’P’, ’R’, ’O’, ’2’. We cant use toupper function.
void ConvertUpper(char S[], int n)
{
int i;
for (i = 0; i < n; i++) {
/* if the characters are in lower case, convert them to
upper case by subtracting 32 from their ASCII value. */
if(S[i] >= 'a' && S[i] <= 'z') {
S[i] = S[i] -32;
}
printf("\n uppercase letters: %c",S);
}
}
int main()
{
char S[7] = {'C', 'o', 'M', 'p', 'r', 'O', '2'};
ConvertUpper(S,7);
}
Step by step
Solved in 4 steps with 2 images