"Sean Bartholomew" <> wrote in message
news: om...
> im trying to parse my email file located in my system library on my
> mac osx.
> i have a form online that, when filled and submitted, is sent to my
> email address.
> i need to parse the fields that were filled out ignoring all the ip
> and complicated stuff around it.
> for eg. im trying to at least get the first block of text that ONLY
> includes the fields and their values.
>
> char *tempBuf;
> ofstream testText ("/Volumes/iBook Docs/Documents/testText.txt");
>
> char *start = strstr(buffer, "First Name=");
> if (start != NULL)
> {
> strcpy(tempBuf, start);
> char *stop = strstr(buffer, "Submit=");
> if (stop != NULL)
> {
> tempBuf[stop - start] = '\0';
> testText << tempBuf;
> testText.close();
> }
> }
>
> it DOES NOT WORK.
> also, "stop - start" works out to a negative value, what gives???
> "testText << start"...."testText << stop"....WORKS (prints a file
> beginning from those exact positions) only if i comment out the
> ---"tempBuf[stop - start] = '\0';"---"
> EVEN if i turn it around to... "start-stop"... so that the value is
> positive.
>
> once i do ANYTHING with "start" or "stop", cast them and copy them to
> integers, or other char variables, ANYTHING, ..."testText <<
> start"...PRINTS OUT AN EMPTY FILE.
> but i need to find out the length between start and stop so that i
> could insert a null character for the 1st record. once thats done i
> could use strtok to parse the fields, which happen to be RETURN
> delimited, but thats fine. i could deal with that. another thing
> is...strstr DOESNT work with "\r".
>
> and ANOTHER thing is, if i insert ...
> testText << buffer;....
> just before the ...testText << tempBuf;...it prints out a file
> beginning with the start address... ie. from "First Name=", NOT FROM
> THE BEGINNING OF THE EMAIL. so it means that buffer is being messed
> with EVEN though i copied it to tempBuf and didnt touch it afterward.
>
> please someone, tell me whats going on, my hair is long and its going
> to be very short, VERY soon.
Sounds like you are causing undefined behaviour by doing something with
pointers that you shouldn't, e.g. not initialising them, or not allocating
enough memory to hold all the data you are copying to them.
To know what is wrong however, we need to see a *complete* program. Snippets
of code doesn't cut it, because inevitably the mistake is in the code you
didn't post.
john
|