blank characters to not cout

I'm trying to figure out how to not cout a char left blank. In the program it will allow 80 char however if less are given it couts' a strange pattern. How do I stop the pattern from showing? Thanks for the help.
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
29
30
31
32
33
34
35
36
37
38
39
40
Description:Program lets a user enter up to 80 characters into an array and converts all
the lowercase letters into uppercase. It will not change uppercase letters.
Limitations or issues: limited to 80 char
Credits: Not Applicable
*/
#include <iostream>
using namespace std;

int main()
{
	const int MIN_LOWERCASE = 97;		// Constant for the minimum lowercase ASCII code
	const int MAX_LOWERCASE = 122;		// Constant for the maximum lowercase ASCII code
	const int MIN_UPPERCASE = 65;		// Constant for the minimum uppercase ASCII code
	const int MAX_UPPERCASE = 90;		// Constant for the maximum uppercase ASCII code
	const int SIZE = 81;		// Constant for the size of a line of input
	char line[SIZE];			// Array to hold a line of input
	cout << "Enter a string of 80 or fewer characters: ";
	cin.getline(line, SIZE);

   for (int count = 0; count < SIZE; count ++)
   {
	   if (line[count] <= MAX_LOWERCASE &&		//change lowercase to uppercase and display
		   line[count] >= MIN_LOWERCASE)
	   {
		  line[count] -= 32;
		  cout << line[count];
	   }
	   else if (line[count] <= MAX_UPPERCASE &&	//leave uppercase unchanged and display
				line[count] >= MIN_UPPERCASE)
	   {
		   cout << line[count];
	   }
	   else if (line[count] == line[count])		//display all other characters
	   {
			cout << line[count];
	   }
   }//end for
system ("pause");
return 0;
}//end code 

Enter a string of 80 or fewer characters: Starting Out with C++!
STARTING OUT WITH C++! ╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠
╠Press any key to continue . . .
This is an initialization problem. getline places the read characters into the array. If the inputted characters is 80 characters or less, then the remaining characters are uninitialized garbage.

You should initialize the line array to zero: char line[SIZE] = {0};

Then, you should jump out of your print loop if you see a char that's zero.

for (int count = 0; count < SIZE && line[count] != 0; count ++)
thank you for the help, I just couldn't see how to fix it. All set now though
Topic archived. No new replies allowed.