Hello, I'm having troubles figuring out how to make my program display only sertain parts of a file. Here's what I mean:
The file I lead is this:
Code:
14x80
%
Home
Syntax:
[LET]variable = value
Description:
The asignment operator assigns the variable its left the value of the express
ion on its right. The equal sign symbol is used both for assignment, and cond
itional equivalence operator. To avoid confusion the optional LET keyword may
be used.
&index&
#
%
index
blah blah this is another text
#
So, what I need to do is load the the file but display only the first part of it between the % and the # symbol. I can't think of a way to do it, any ideas will be appreciated.
to explain the first line of code, it's what tells the program the size of the file.
Here is the code I use for loading and dysplaying the file:
Code:
int LoadMap(char mapFile[])
{
ifstream file(mapFile,ios::in);
if(!file)
return -1;
char * sizestr = new char[10];
file.getline(sizestr,10,'\n');
string strsize = sizestr;
delete[] sizestr;
MAPHEIGHT = atoi(strsize.substr(0,strsize.find("x")).c_str());
strsize.erase(0,strsize.find("x")+1);
MAPWIDTH = atoi(strsize.c_str());
int ycounter = 0;
while(ycounter < MAPHEIGHT)
{
file.getline(map[ycounter],1000,'\n');
ycounter++;
}
file.close();
return 0;
}
void DrawMap(int mapheight, int mapwidth)
{
color(FWI|BNULL);
for(int ycounter = 0; ycounter < mapheight; ycounter++)
{
gotoxy(2,ycounter+1);
for(int xcounter = 0; xcounter < mapwidth; xcounter++)
{
if(map[ycounter][xcounter] == '#')
{ycounter=mapheight;}
else
cout << map[ycounter][xcounter];
}
}
}
Thanks in advance.
--aroticoz