   text file parsing...
  What's wrong with this?  if(!file)    {file = fopen(path,"r");bool done=false;while(!done){ fscanf(file,"%s",string); if(string[0] == (int)'@') { if(strcmp(string,"@BEGIN ")) {  fscanf(file,"%s",string);  int n = atoi(string);  fprintf(out,"%d\n",n);  if(n == id)  {   done=true;   read_data=true;   line_count=0;   mx=x;   my=y;  } } } if(feof(file)) break; }    }What I'm trying to do is search a text file for tags called "@BEGIN" now after the begin there supposed to be a number like "@BEGIN 1" if the number matches then it's done and it keeps going to the next section of code the problem is it only reads the tag once after that the number (n) only equals zero...I hope that made some sense anyway I'm sure it's just a stupid mistake but I can't get it to work...[edited by - JohnyB on July 30, 2003 11:18:25 PM]
  First off, I would get rid of the check for (!file). It''s unnecessary. The main error I see is:strcmp is implemented to return 0 if the two strings are equivalent, not 1, as your code will check for. Change the if(strcmp()) to if (strcmp()==0). I would also recommend learning how to use stream objects for file I/O, especially for a c++ text parser. If you have any more questions, ask. I dont quite understand what your algorithm is supposed to do...so maybe I can help more if you explain it more. What is the fprintf for?   Brian JDL Vacuum - A media file organizer I made | Mumbling Miles - A band I was the guitarist/vocalist for ;  The sign of the result of strcmp can be used to tell if the first argument comes before (negative) or after (positive) the second, and, as bjmumblingmiles pointed out, 0 means they are equal.   [edited by - smart_idiot on July 30, 2003 11:36:22 PM];  Okay I changed the strcmp check to equal zero but still nothing that's strange because the code seemed to work anyway. About the fprintf function forget it it's not very important it's just another file that I'm using to see the value of n each time that the code is run. And I know how to use streams but I can't use them because for some reason when I installed DevC++ it didn't come with iostream.h or fstream.h  so I'm just using stdio. Ok here's what I want the function to do I want to have a text file like:@BEGIN 1some string@BEGIN 2another string...then I want to be able to call a function that reads something like DisplayString(number); ...so if I set the number to 1 then it displays whatever is in one,etc..    [edited by - JohnyB on July 30, 2003 12:24:27 AM];  Add ...\include\c++\mingw32 and ...\include\c++\backward to the c++ includes in the compiler options, and drop the .h from those so it is #include<iostream> and #include<fstream>. It should work.Stupid HTML messing up my post.   [edited by - smart_idiot on July 30, 2003 12:36:18 AM];  Oh yeah it works now thanks I didn''t notice it was in a different dir I guess I got too used to the older version. Anyway I still want to try to solve the problem so I know what I''m doing wrong any ideas?  ;  Okay never mind I rewrote the code and it works perfect now thanks for the help! 