By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,167 Members | 1,044 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,167 IT Pros & Developers. It's quick & easy.

Strang output??

P: 6
I am perplexed at the output from this cout statement. The code for the function is:
Expand|Select|Wrap|Line Numbers
  1. int print_func(int pr_number_row, int pr_number_column)
  2. {
  3.         int count_row = 0, count_column = 0;
  4.         while(count_row <= pr_number_row)
  5.         {
  6.                 while(count_column <= pr_number_column)
  7.                 {//Prints every space in the array
  8.                         //This is the dysfunctional cout statement
  9.                         cout << battle_array[count_row][count_column] << " ";   
  10.                         count_column++;
  11.                 }
  12.                 count_column = 0;
  13.                 count_row++;
  14.         }
  15.         system("pause");
  16.         return(0);
  17. }
  18.  
What's weird is that if i try and execute this function, the space at the end of the cout will not output along with the system("pause"); at the end of the code. As i was trying to fix this I found that if I wrote the statement like this:

Expand|Select|Wrap|Line Numbers
  1. cout << "aaa" << battle_array[count_row][count_column] << " ";
  2.  
Where any 3 characters fill that space in the front it will print the last space a the end and pause the program. I have never had such a strange error. I was wondering if it was my compiler(Borland C++ Builder 6) or if I just made a mistake in the code of the function?? Or maybe it is a problem from the function that I call this function from.
Feb 20 '07 #1
Share this Question
Share on Google+
4 Replies


100+
P: 1,646
And what, prey tell, is lurking within battle_array??
Feb 20 '07 #2

P: 6
And what, prey tell, is lurking within battle_array??
Well its supposed to be a game, so some objects. Im still having the problem though. Its really starting to make me angry, because the array has integers in it so to show a difference i changed the integers to letters like this:
Expand|Select|Wrap|Line Numbers
  1. void print_func(int pr_number_row, int pr_number_column)
  2. {// 0 = #, 1 = new X, 2 = old X, 3 = new O, 4 = old O
  3. // this function outputs the section of the array being used
  4.         int count_row = 0, count_column = 0, nl_count = 0, change_letter;
  5.         while(count_row <= pr_number_row)
  6.         {
  7.                 while(count_column <= pr_number_column)
  8.                 {//Prints every space in the array
  9.                         change_letter = battle_array[count_row][count_column];
  10.                         if(change_letter == 0)
  11.                         {
  12.                                 cout << "# ";
  13.                         }
  14.                         else if(change_letter == 1)
  15.                         {
  16.                                 cout << "x ";
  17.                         }
  18.                         else if(change_letter == 2)
  19.                         {
  20.                                 cout << "X ";
  21.                         }
  22.                         else if(change_letter == 3)
  23.                         {
  24.                                 cout << "o ";
  25.                         }
  26.                         else if(change_letter == 4)
  27.                         {
  28.                                 cout << "O ";
  29.                         }
  30.  
  31.                         if(nl_count == pr_number_column)
  32.                         {
  33.                                 cout << endl;
  34.                         }
  35.                         nl_count++;
  36.                         count_column++;
  37.                 }
  38.                 count_column = 0;
  39.                 nl_count = 0;
  40.                 count_row++;
  41.         }
  42.         system("pause");
  43. }
  44.  
Now when change_letter == 0 it does not display because of the problem stated above. I have no clue what the hell is wrong, because i have rewritten the function and changed many things I just cant figure it out. Also if i make another function and call it in here it becomes corrupt as well.
Feb 22 '07 #3

RedSon
Expert 5K+
P: 5,000
Did you try putting a << endl; at the end of your cout? If you do " " << endl then the compiler will operate on your whitespace before inserting a new line from endl
Feb 22 '07 #4

P: 6
Did you try putting a << endl; at the end of your cout? If you do " " << endl then the compiler will operate on your whitespace before inserting a new line from endl
well for instance the first example i gave

cout << "aaa" << battle_array[count_row][count_column] << " ";

also lets say battle_array[count_row][count_column] = 6

This would give output as "6 ", but no aaa where did they go??
To day i had changed some code in a different function and it started to print tabs for the "aaa". Where did these tabs come from?? Again the aaa did not print. There is no explanation, other than something in my other functions is affecting everything above it making it output weird.
Feb 22 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.