Segmentation Fault?!?

S

Shadow503

Here is my code:
#include <iostream>


using namespace std;

int vWidth;
int vHeight;
char mapdata[999][999];
/* Map Data Array
x-Boundary
~-Water
o-Island
*/

void drawmap (){
cout << "\n";
int i;
int j;
i=0;
j=0;
while (mapdata[0]!='x'){
while (mapdata[0][j]!='x'){
cout << mapdata[j];
j++;
}
i++;
}


}

int main(){
cout << "Enter the Width of the map:\n";
cin >> vWidth;
cout << "Enter the Height of the map:\n";
cin >> vHeight;
int i;
//Set boundries
for (i=0; i<=vHeight; i++) {
mapdata[vWidth]='x';
}
for (i=0;i<=vWidth; i++){
mapdata[vHeight]='x';
}
//Draw the map
drawmap ();
return 0;
}

I keep getting a segmentation fault error after I enter the height.
I'm on Ubuntu 6.06, using the Anjuta IDE and compiling with g++.
 
R

red floyd

Here is my code:
#include <iostream>


using namespace std;

int vWidth;
int vHeight;
char mapdata[999][999];
/* Map Data Array
x-Boundary
~-Water
o-Island
*/

void drawmap (){
cout << "\n";
int i;
int j;
i=0;
j=0;
while (mapdata[0]!='x'){
while (mapdata[0][j]!='x'){
cout << mapdata[j];
j++;
}
i++;
}


}

int main(){
cout << "Enter the Width of the map:\n";
cin >> vWidth;
cout << "Enter the Height of the map:\n";
cin >> vHeight;
int i;
//Set boundries
for (i=0; i<=vHeight; i++) { use <, not <=
mapdata[vWidth]='x';
}
for (i=0;i<=vWidth; i++){ use <, not <=
mapdata[vHeight]='x';
}
//Draw the map
drawmap ();
return 0;
}

I keep getting a segmentation fault error after I enter the height.
I'm on Ubuntu 6.06, using the Anjuta IDE and compiling with g++.


What are you entering for width and height? If you enter 1000 or
more, you're toast.
 
S

Shadow503

Here is my code:
#include <iostream>
using namespace std;
int vWidth;
int vHeight;
char mapdata[999][999];
/* Map Data Array
x-Boundary
~-Water
o-Island
*/
void drawmap (){
cout << "\n";
int i;
int j;
i=0;
j=0;
while (mapdata[0]!='x'){
while (mapdata[0][j]!='x'){
cout << mapdata[j];
j++;
}
i++;
}

int main(){
cout << "Enter the Width of the map:\n";
cin >> vWidth;
cout << "Enter the Height of the map:\n";
cin >> vHeight;
int i;
//Set boundries
for (i=0; i<=vHeight; i++) { use <, not <=
mapdata[vWidth]='x';
}
for (i=0;i<=vWidth; i++){ use <, not <=
mapdata[vHeight]='x';
}
//Draw the map
drawmap ();
return 0;
}

I keep getting a segmentation fault error after I enter the height.
I'm on Ubuntu 6.06, using the Anjuta IDE and compiling with g++.

What are you entering for width and height? If you enter 1000 or
more, you're toast.



I know. I found the main bug anyways, but thankyou for your help.
Switching around the operators helped also. I needed to switch around:
mapdata[vHeight]='x';
With:
mapdata[vHeight]='x';
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top