while (*p++);
-
With your solution p will point to the first NULL from the beginning, which is not really correct. it will point to the char after the first null. try to trace it and see. but be careful with the string you use, or your program might crash. for eg, use "a\0bb\0ccc\0\0dddd" I can understand, the code is very deceptive. only a few get it right the first time, and I am not one of them either :) thanks!
Lets make it more accurate then:
// UNOPTIMIZED
//////////////////////////
343: char* p = "123";
0043CA51 mov dword ptr [ebp-14h],offset string "123" (004df014)
344: while( *p++ ) {};
0043CA58 mov eax,dword ptr [ebp-14h] // eax <- p
0043CA5B movsx ecx,byte ptr [eax] // value_type = p[0];
0043CA5E mov edx,dword ptr [ebp-14h] // edx <- p
0043CA61 add edx,1 // edx <- edx + 1
0043CA64 mov dword ptr [ebp-14h],edx // p <- edx
0043CA67 test ecx,ecx // if( ecx is 0 )
0043CA69 je main+4Dh (0043ca6d) // goto 0043CA6D
0043CA6B jmp main+38h (0043ca58) // goto 0043CA51
345: return 0;
0043CA6D xor eax,eax
0043CA6F jmp __tryend$_main$1+2Ch (0043cac0)// UNOPTIMIZED
START_LOOP:
value_type = *p;
++p;
if( value_type == 0 )
goto END_LOOP;
goto START_LOOP;
END_LOOP:INTP Every thing is relative...