195k views
2 votes
How to write a program in HCS12 / 9S12 to convert all the lowercase letters in a string into uppercase?

a) Use the "toupper()" function
b) Utilize ASCII codes
c) Apply the "strupper()" method
d) Implement a loop with "toupper()" function

1 Answer

2 votes

Final answer:

To convert all the lowercase letters in a string into uppercase in HCS12 / 9S12, you can implement a loop with the toupper() function.

Step-by-step explanation:

To convert all the lowercase letters in a string into uppercase in HCS12 / 9S12, you can implement a loop with the "toupper()" function. Here are the steps:

  1. Declare a string variable to store the input string.
  2. Iterate through each character in the string.
  3. Inside the loop, use the "toupper()" function to convert each lowercase letter to uppercase.
  4. Replace the original lowercase letter with the uppercase letter.
  5. Continue until all characters in the string have been checked and converted.

Here's an example in C:

#include<stdio.h>
#include<ctype.h>

int main() {
char str[100];
int i;

printf("Enter a string: ");
fgets(str, 100, stdin);

for (i = 0; str[i] != '\0'; i++) {
if (islower(str[i])) {
str[i] = toupper(str[i]);
}
}

printf("Uppercase string: %s", str);

return 0;
}
User Liruqi
by
7.8k points