Answer to Question #34723 in C++ for Gregory

Question #34723
this piece of code is supposed to delete spaces in the char array "a b c d e";
the first one works properly, the second one doesn't;
what is the difference between them?
-----1-----
int i = 0, j = 0;
while((*(str + i) = *(str + j++)) != '\0'){
if(*(str + i) != 32)i++;}

-----2-----
int i = 0, j = 0;
while(*(str + j) != '\0'){
*(str + i) = *(str + j++);
if(*(str + i) != 32)i++;}

Isn't it basically the same?
But the first one returns ->'abcde'
while the second one returns ->'abcde d e'.
T_T
0
Expert's answer

Answer in progress...

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS