首页 > 代码库 > while(i<256&&buff[i]==' ')i++; VS while(i<256 && buff[i++]==' ');
while(i<256&&buff[i]==' ')i++; VS while(i<256 && buff[i++]==' ');
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++]==' ');
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。