码迷,mamicode.com
首页 > 其他好文 > 详细

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

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

标签:style   blog   io   ar   color   sp   on   div   log   

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++]==' ');

标签:style   blog   io   ar   color   sp   on   div   log   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!