Look at the new and delete[] keywords and use myFileStr as the max size, or try
Qt which has QString :)

On Thu, 02 Sep 1999, you wrote:
> Hi,!
> 
> Yeah Mofset I figureout the problem of a pointer with 0 length.. but how
> should I write my function so?
> How could we declare a char that we dont know the max size? Iam really
> confused.  I tough declaring a char *NextSearchPtr will dynamicly increase
> the size... ????
> 
> Damn transition to vb to pure c++ is a nightmare but c++ was so powerfull!
> 
> gimme clue!
> 
> Thanks for your help! (sorry for my bad english)
> 
> emman
> 
> Emmanuel Par�
> GIS/Programming for DBX Geomatics
> email:[EMAIL PROTECTED]
> http://www.linux-mandrake.com
> 
> -----Original Message-----
> From: Mosfet <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>; Emmanuel Par�
> <[EMAIL PROTECTED]>; [EMAIL PROTECTED] <[EMAIL PROTECTED]>
> Date: 2 septembre, 1999 10:54
> Subject: Re: [Cooker] My Other question to C++ Geeks
> 
> 
> NextSeachPtr is a pointer with no memory allocated. It's pointing at random
> data (or more likely NULL). Thus when you copy data to it it will segfault.
> That is why it is working with the [3000], you are allocating 3,000 bytes
> there.
> 
> On Thu, 02 Sep 1999, Emmanuel Par� wrote:
> > 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
> --
> Daniel M. Duley - Unix developer & sys admin.
> [EMAIL PROTECTED]
> [EMAIL PROTECTED]
> [EMAIL PROTECTED]
-- 
Daniel M. Duley - Unix developer & sys admin.
[EMAIL PROTECTED]
[EMAIL PROTECTED]
[EMAIL PROTECTED]

Reply via email to