convert lowercase to uppercase string

i need to convert a line of text to all uppercase, but i am stuck, when i type in the line of text, it outputs only one word from that whole line.
ex:
Hello World!

output:
HELLO

i need that whole line to be uppercase or any line that i input. please help me. thank you.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <cstring>
using namespace std;

void convert_to_uppercase(char str[])
{
    for (int x = 0; x < strlen(str); x++)
    {
        if (str[x] >= 97 && str[x] <= 126)
        {
            str[x] -= 32;
        }
    }
}

int main()
{
    char text[100];

    cout << "Enter a line of text" << endl;
    cin >> text;

    convert_to_uppercase(text);

    cout << text << endl;

}
Last edited on
Replace cin >> text; with cin.getline(text, 100);.

Also, you can just use std::toupper in <cctype>.
At the very least, you can use if (str[x] >= 'a' && str[x] <= 'z') instead of having to look up the ASCII values for those characters.
Last edited on
That's not your code problem. istream (cin) gets since it finds a space. You should use cin.getline(text, 100) instead cin >> text.
ok it works, thank you guys a lot!
Topic archived. No new replies allowed.