Index « Previous Next »

Question

Write a program that prompts the user to input a string and outputs the string in uppercase letters.

Source Code

#include <stdio.h>

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

    printf("Enter a string: ");
    gets(str);

    for (i = 0; str[i] != '\0'; i++)
    {
        str[i] = (str[i] >= 'a' && str[i] <= 'z') ? (str[i] - 32): str[i];
    }

    printf("\nConverted string: %s", str);

    return 0;
}

Output

Enter a string: Computer science

Converted string: COMPUTER SCIENCE