首页 > 其他 > 详细

while(i<256&&buff[i]==' ')i++; VS while(i<256 && buff[i++]==' ');

时间:2014-11-21 16:04:27      阅读:332      评论:0      收藏:0      [点我收藏+]

here we just want to divide a simple string with blank space within it , such as " hello world " .

char buff[256]=" hello  world ";

and we have two general well-programmed source solution : 

soluation 1 : 

while( i < 256 && buff[i++] ==   );

we use the above code to skip the head blank space on hello

but it rush to i=2 ! but we just have a single blank space on hello

and here we have a normal solution : 

while( i<256 && buff[i]==  )i++;

in this way , we get the first NOT blank i=1;

in face , when we use the first ways , i=0 , it satisfy the loop condition , and i=1;

when i=1 , it can not satisfy the condition , but i will increment itself automatically !!!

be careful !

 

while(i<256&&buff[i]==' ')i++; VS while(i<256 && buff[i++]==' ');

原文:http://www.cnblogs.com/dragen/p/4113035.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!