Quote Originally Posted by thames View Post
Thank you for the compliment. But what does that ".0" mean? a kind of junk ?
Not really. This is what was left by previous call.

I will use your own - beautiful - in my mind explanation ( which i really appreciate and thank you for that, because it really gave me the answer in a question i was thinking all the time in bed the last night. Thank you again .)

See the following breakpoints
Without the s[1] = '\0';

Code:
Breakpoint 3, getop (s=0x7fffffffe640 "2.5") at reversepolish.c:111
111       return NUMBER;  
(gdb) cont 
Continuing.
 
Breakpoint 1, getop (s=0x7fffffffe640 "+.5") at reversepolish.c:99
99        return c; /* not a number */
(gdb) cont 
Continuing.
Now with the s[1] = '/0';
Code:
Breakpoint 3, getop (s=0x7fffffffe640 "2.5") at reversepolish.c:111
111       return NUMBER;  
(gdb) cont
Continuing.
 
Breakpoint 1, getop (s=0x7fffffffe640 "+") at reversepolish.c:99
99        return c; /* not a number */
(gdb) cont
Continuing.
So in the first call we have 2.5 inside s <- the parameter of getop.
Then we get the plus operator ( + ) .
If we remove line s[1] = '\0' (first piece of code) then we have in the buffer 2.5 , but then when we read the + operator, because it is only one element - one cell, only the first element of the buffer is going to be overwritten, while the the second (had the '.' from previous call) and third (had the '5' from previous call) elements will not be overwritten.

As a result in the second call of getop we will have inside the buffer +.5

Now ,with the line s[1]='\0'; we have in the first call of getop 2.5 inside the buffer and in the second call we have + inside the buffer , which is what we want

Then in the last three breakpoints you have , you receive in the first call of the function 4.0 , thus buffer gets the 4.0 as content of it.Then you read * , but without the s[1]='\0' line you will get *.0 . The dot and the zero come from the 4.0 , because again only the first element of buffer (array s) will be overwritten.

Can you understand what i am saying?

Again thank for this beautiful question and your nice breakpoints