Oh. I got what you mean. You want to eliminate unnecessary spaces that users might have keyed in. Is that right?
Ok, the simplest solution is to use string stream.
Suppose that you captured the user's original input in the array "input". Now the code to trim those unnecessary spaces is as follows:
Code:
//suppose the result is stored in the char array "st1"
char temp[1000];
//put the original input into a string stream
istrstream in(input);
//initialize st1 to be an empty, non-null string
strcpy(st1, "");
while(true){
//read in one word from the stream. it will read until a space is encountered,
//and the space is ignored.
in >> temp;
if(in.good()){
//so now we append this word, and a space to the end of st1.
strcat(st1, temp);
} else {
//if the stream is empty already, it's done.
break;
}
}
//so now we have an extra space at the end of "st1", we just have to trim it
st1[strlen(st1)] = 0;