Maybe Pixel can help me with this one...

Recently I have store a entire into a string that work very nice!  Now my
problem is the parsing of that file..  I need to find the 2th occurance of a
string ex : "WINS" in my MyFileStr.  Since strstr only return the first
occurance I must do a loop and increment the pointer.  But my problem is
very stupid I dont how to strcpy myFileStr ro NextSearchPtr the problem I
think is the declaration of NextSearchPtr if I declare it like char
NextSearchPtr[3000]; (<- not elegant)  its ok for the strcpy but not work in
the function (not a pointer),... Damn I am really confuse...

A C++ beginner..

emman


Function to find the number of occurance of a string in a big string..

void ipobject::scanFile()
{

 myFileStr = "some text WINS here WINS, WINS!";

 char *NextSearchPtr;
 char *searchstr= "WINS";
 int Compt=1;

//just adding a safe null caracter at the end of the array
  myFileStr[strlen(myFileStr)] = '\0';

  strcpy(NextSearchPtr,myFileStr);

    do {
      NextSearchPtr = strstr(NextSearchPtr, searchstr);
      ++NextSearchPtr;
      Compt++;
      } while(NextSearchPtr != NULL);

      cout << Compt;
}



Emmanuel Par�
GIS/Programming for DBX Geomatics
email:[EMAIL PROTECTED]
http://www.linux-mandrake.com

Reply via email to