Prob with an Array

Hey all

Im trying to convert a lower case string to all uppercase using the ascii table.. I ask the user to input a string which i then put into an array of char's.

The printing of the uppercase version is where im having trouble i can get it to print the first word of the sting but nothing more its like its stopping the array after the first white space.. its prob a simple fix that ill be like ahhh i should have got that but its just tricking me up at the moment.. any help will be muchly appreciated.

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
28
#include <iostream>
using namespace std;
using std::cout;
using std::endl;

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


int main()
{

        char s1[50];
	int i=0;

	cout<< "Please now enter a String in lowercase: "<<endl;
	cin>> s1;
	
	for (int i=0; s1[i]; i++)
	{
		s1[i] = toupper (s1[i]);

	}

	cout<<s1[7]<<endl;//Trying to see whats in position 7 of the array.

	
	cout<<"the upperCase version is: "<<s1<<endl;
Since this is C++, you should be using std::string, not character arrays.

std::cin is only reading in one word using the >> operator.

Try:

1
2
3
cout<< "Please now enter a String in lowercase: "<<endl;
string s1;
getline(cin, s1);


Topic archived. No new replies allowed.