Sign in to follow this  

how to start loading from file at a certain string?

This topic is 4388 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Say that I have a data file and in that data file there is an image name that every thing uses then there is names and after the anmes and need to load everything then stop at at certain string I scan the data file for anything that starts with AnimName and the next word after it gets loaded. then I want to go back and use the string it found and load all the info after it tell it runs into } example File null.bmp AnimName BallSpin Left 0 <- start loading Right 92 Top 0 Bottom 0 Red 0 Green 0 Blue 0 Delay 0 Width 0 FrameW 0}<- sees } and stops loading AnimName BallExplode <- then when BallExplode string is slected the prosses Left 0 starts over Right 92 Top 0 Bottom 0 Red 0 Green 0 Blue 0 Delay 0 Width 0 FrameW 0} I can parse the file find the strings and load the data I just can start at a sertin point and stop at another it just goes all the way though.

Share this post


Link to post
Share on other sites
For a quick fix, assuming you're reading line by line, just place the '}' on it's own line - in this case under "FrameW 0".

EDIT: ahh just realised your problem. Instead of retracing your steps, you may want to read everything from the file all at once.

Share this post


Link to post
Share on other sites
So how would I read in the whole file at once and keep every thing orginized?

void parse(ifstream & fin)
{
string s;
int flt;

while (fin >> s)
{

// if (s == SelString)
//{
//Image file name
if (s == "File" )
{
fin >> imageName;

}
if (s == "Right")
{
fin >> ImRight;
}
if (s == "Left")
{
fin >> flt;
ImLeft = flt;
}
//image hight
if (s == "Top")
{
fin>> flt;
ImTop = flt;
}
if (s == "Bottom")
{
fin>> flt;
ImBottom = flt;
}
//image traspartne color for RGB
if (s == "Red")
{
fin >> flt;
TC1 = flt;
}
//image traspartne color for RGB
if (s == "Green")
{
fin >> flt;
TC2 = flt;
}
//image traspartne color for RGB
if (s == "Blue")
{
fin >> flt;
TC3 = flt;
}
//Number of frames
if (s == "#")
{
fin >> flt;

NumFrames = flt;
}
//the delay time between frames
if(s == "Delay")
{
fin >> flt;
DTime = flt;
}

//width of the whole image
if(s == "Width")
{
fin >> flt;
ImWidth = flt;
}
//width of frame
if(s == "FrameW")
{
fin >> flt;
FrWidth = flt;
}

//ignore ;
if (s == ";")
{
fin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
}

//ignore //
else if (s == "/")
{
fin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
}
//ends the search
else if (s == "}")
{
MessageBox(hwnd,"failed","Error",0);
return;
}
// }
}
}



//loads animation type to drop down box
int AnimTypeLoader(ifstream & fin)
{
string s;

while (fin >> s)
{

//Animation number
if (s == "AnimName" )
{
fin >> FileName;
list1.push_back(FileName);//add to all iteams to list
}
}
//SendMessage(hwndCombo1, CB_RESETCONTENT, 0, 0);
while (list1.size() > 0)//add
{//add
string value = list1.front();//add
SendMessage(hwndCombo1,CB_ADDSTRING , 2,(LPARAM)value.c_str());
list1.pop_front();//add
}//add
SendMessage(hwndCombo1,CB_SETCURSEL, 0,0);

int nIndex = SendMessage( hwndCombo1 , CB_GETCURSEL, 0, 0 );
SendMessage(hwndCombo1,CB_GETLBTEXT, nIndex,(LPARAM)SelString.c_str());

}


that is how i read it in

Share this post


Link to post
Share on other sites
My issue is I need to load settings for each animation type. And when animation type is slected from the drop down box it will load the settings associated with that type.

With that in mind should I use a
struct to stor the data
or
an array index of some sort

if any one can think of a better way just let me know.

Share this post


Link to post
Share on other sites

This topic is 4388 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this