Brooke, Pamela, Carmen Elektra
Michelle Johnson, Dennis Doe, Clifford Robinson
Code:
#include<cstring>
...
char name1[32];
char name2[32];
int len;
...
//in a loop
ifstream.getline(name1,16,' ');
len=strlen(name1);
if(name1[len]=',') //if this was the only name
name1[len-1]='\0'; //get rid of that last char (and comply with c-string definition)
else //if there's another word comming
{
ifstream.getline(name2,32,' '); // take it in
name2[strlen(name2)-1]='\0'; //remove the comma and put null-termiator in
}
//now you have the name
...
//end loop
...
this is assuming your file follows this:
[fname],
-or-
[fname] [lname],
with a space between each name and after each comma... no spaces before the comma... if your file doesn't follow these rules, this won't work... but you should definately get your input to follow some kinda ruleset...
__________________________________________________ __
EDIT: just read your OP again... just follow what codeplug said...mod it to do what you need
Code:
infile>>name1>>name2;
cout<<name1;
if(strcmp(name2,",\0")) //if name2 is not a comma
cout<<name2;
cout<<endl;
of course this assumes you're using C-strings... which nobody uses anymore