Hi, I'm having some trouble making this program work, and I thought another set of eyes might help. I'm also hoping that I could get some suggestions to improve it from its current form. I've been staring at this screen for hours and my eyes are totally shot. Anyway, what I'm trying to do is use a character pointer to slide along the string so I can extract all of the From: and Subject fields so they look something like:
1. Jim Zoo
2. Lauren Hey
I also thought I might simplify things a bit by terminating each message with a unique character, so i don't have to do the size check or the x++, and maybe build my loop clause to check for the special char. anyway, i'm exausted and can't revise this code anymore tonight, but I hope someone can offer me some tips on how to improve it. Thanks.
Code:
string msg = ">From: Jim\nTo: Lauren\nSubject: Zoo\nMessage: blah\n>From: Lauren\nTo: Jim\nSubject: Hey\nMessage: blah\n";
string s = msg;
const char *pointer = msg.c_str();
int x=0;
int size = s.length();
while (x< size) {
pointer = pointer + 7; //pointer shift to end of first FROM
x + 7;
string temp;
while (*pointer != '\\') { // the while does have double slashes, just doesn't show up in the code here
temp = temp + *p;
pointer++;
x++;
} //iterate along the string until first \ character is reached
cout<<"From is "+temp<<endl;
pointer= pointer+2; //skips us past the \n character
x=x+2;
while (*pointer !='\\') {
pointer++;
x++;
} //slide along until we get to the subject
pointer = pointer+2;
x=x+2;
pointer=pointer + 7;
x=x+7; //skip past subject word
string temp_two;
while (*pointer !='\\') {
temp_two = temp_two + *p;
pointer++;
x++;
} //get the subject
cout<<"subject is"+temp_two<<endl;
pointer = pointer+2;
x=x+2;
while (*pointer !='\\') {
pointer++;
x++;
}//slide along to get past the message
}
//cout << "\n\tPress any key to return to the main menu";
// getchar();
}
btw, it compiles fine, but it crashes when I run the executable