On Jul 27, 10:20 am, Blip <b...@krumpli.comwrote:
I try to update the buffer pointer in a switch statement like this:
buf[ptr]=(serialinput);
switch (buf[ptr++])
that doesn't work correctly -- doesn't update the ptr
<snip>
What value do you want the switch statement to test? If it's the
pointer *before* it is incremented, then your code is right (well not
really, see below). If you want it to be the pointer *after*
incrementation, then you have to do a pre-increment:
buf[ptr]=(serialinput);
switch (buf[++ptr]) { ... }
Also, the names of the variables leads me to believe the code is wrong
anyway. 'ptr' is a pointer, right? You can't subscript an array (or a
pointer) with a pointer; you subscript it with an integer. If 'ptr'
points to an element in the array (or pointer) 'buf', then the code
should look like this:
*ptr = (serialinput);
switch (*++ptr) { ... }
Sebastian