Loading
September 18, 2014, 09:45:07 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Welcome!
 
   Forum Home   Help Search Forum Login Register  
Pages: [1]   Go Down
  Send this topic  |  Print  
Author Topic: bug in console program  (Read 1449 times)
ubuntucuber
Newbie
*
Posts: 24


design made on computer


« on: April 08, 2011, 08:02:45 PM »

I an trying to figure out why this program will  compile, and execute, however does not display any data that is part of the program.
Code:
#include <iostream>
#include <cstdlib>
using namespace std;

int main (int argc, char *argv[]) {
char buffer[23][80];
for(int a = 0; a < 23; a++) {
for(int b = 0; b < 80; b++) {
buffer[a][b] = ' ';
}
}
char in[80];
char text[75];
int x, y;
bool quit = false;
cout << endl;
while (quit == false) {
cin.getline(in, 80);
if(in[0] == 'r' && in[1] == 'e' && in[2] == 's' && in[3] == 'e' && in[4] == 't') {
for(int a = 0; a < 23; a++) {
for(int b = 0; b < 80; b++) {
buffer[a][b] = ' ';
}
}
} else {
x = atoi((const char*)in[0]) * 10 + atoi((const char*)in[1]);
y = atoi((const char*)in[2]) * 10 + atoi((const char*)in[3]);
for(int a = 4; a < 80; a++) {
buffer[y][x + a - 4] = in[a];
if((int)in[a] == 0) {
buffer[y][x + a - 4] = ' ';
}
}
}
cout << endl;
for(int a = 0; a < 23; a++) {
for(int b = 0; b < 80; b++) {
cout << buffer[a][b];
}
}
}
return 0;
}

And the output:
Quote
bash: line 1:  2209 segmentation fault          /home/LINUXHATER/Projects/consolegui/bin/Debug/consolegui

Also, I am ironically using ubuntu linux, MonoDevelop IDE and Geany with g++ compiler

Edit:Geany also gives the same error.
« Last Edit: April 11, 2011, 10:59:34 PM by ubuntucuber » Logged
Michael Hall
Administrator
Hero Member
*****
Posts: 970



« Reply #1 on: April 09, 2011, 03:37:34 PM »

FYI, it is not possible for anyone to help debug this unless you let us know what you are entering and what you expect as a result. You must be entering something for the cin.getline() command. We need to know what that is.

Mike
Logged
ubuntucuber
Newbie
*
Posts: 24


design made on computer


« Reply #2 on: April 09, 2011, 10:02:10 PM »

The string I entered at cin.getline() is "0123set" which should print the word set on the second line starting at position 23. I should then be able to enter "0000random_phrase" which would also print the text random phrase in the top left corner while still showing the word set at the right position.
Logged
SaMaN
Newbie
*
Posts: 1


« Reply #3 on: May 23, 2011, 09:47:54 AM »

Try to clear the buffer.
Logged
ubuntucuber
Newbie
*
Posts: 24


design made on computer


« Reply #4 on: June 07, 2011, 09:42:56 PM »

How would I do that?
Logged
Pages: [1]   Go Up
  Send this topic  |  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!