>>How can I monitor every little step of the function like that?
1) use a debugger
or
2) take a short test string and follow it manually. For example: "H W". Initially variables i and j are both 0, so it will just copy the character 'H' onto itself, then increment j so that j points to the space. Next it asks if i points to a space, and if it does not then incremenet i.
Second loop iteration: i and j are both 1 and both point to the space. So it will copy the space onto itself, then ask if i points to space. It does in this case, so it will NOT increment i.
Third loop iteration: i = 1 and j = 2 so it copies the 'W' onto the space. j is incremented to 3 and since the character at i is now a 'W' instead of a space the value of i is incremented to 2.
The string now looks like this: "HWW"
Fourth loop iteration: i = 2 and j = 3. The string's null terminator is copied to the second 'W' in the string so that the string is contains this: "HW". The whole thing stops because it just copied the '\0' character.
Last edited by Ancient Dragon; Dec 3rd, 2008 at 9:13 am.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Offline 21,947 posts
since Aug 2005