Coded in C++.
Code: Select all
void playerInput()
{
shipType = Player[0];
shipColumn[0] = Player[3];
shipColumn[1] = Player[4];
int Playerlen = Player.length() - 1;
int dirBegin = Player.find(' ') + 2;
cout << Playerlen << " " << dirBegin;
//Converts the alphanumerical character to ASCII integer
e = static_cast<int>(Player[2]) - 65;
//column indication
d = atoi(shipColumn) - 1;
if(d == 104)
d = 9;
//Puts "down" "up" or any other direction from the Player to shipPlaceDir
for(x = 0; x <= (Playerlen - dirBegin); x++)
{
int y = dirBegin + x;
shipPlaceDir[x] = Player[y];
}
cout << shipPlaceDir;
}
Battleship playerInput() function copyright 2008 Mark Galesic.
(not that u would want to copy my crappy broken code ;) ).
The thing that is bugging me is the "for" statement. For some reason, no errors are given when compiling, but my friend told (we were in the computer lab he had to leave but said he'd help if I didn't get through with the problem) me that its a seg (I'm guessing short for "segment") error.
Anyway, what he thought was that the loop was doing something out of bounds out of one of the strings. Well, I rechecked my math, and saw what I need to do, but I still get the seg error.
Can anybody give me a hint as to what the problem is?