In this exercise, your C program will read characters from keyboard (up to 80) a
ID: 3761097 • Letter: I
Question
In this exercise, your C program will read characters from keyboard (up to 80) and store the characters in a string. The characters could be letters, numbers, punctuations, and spaces. Print this array on the screen (with a new line character). Then your program will call a function called convertString that will take the string and a maximum buffer length as its arguments. The function will convert the lowercase letters in the string and convert them to upper case letters. All other characters should remain the same. In your main program, print the converted string with a new line.
Explanation / Answer
#include <stdio.h>
#include <ctype.h>
void convertString(char input[80], int size)
{
int i = 0;
while(input[i] != '' && i < size)
{
if(islower(input[i]))
input[i] = toupper(input[i]);
i++;
}
}
int main()
{
char input[80];
printf("Please enter characters: ");
fgets(input, sizeof(input), stdin);
puts(input);
convertString(input, 80);
puts(input);
puts("Press any key to continue . . .");
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.