This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Stack problems

I am running this code on an XC161

#include <stdlib.h>
#include <string.h>

#define WIN_MAXTEXT         128
#define WIN_TEXTLEN         21

typedef struct {
  int count;
  int top;
  char caption[WIN_TEXTLEN+1];
  char lines[WIN_MAXTEXT][WIN_TEXTLEN+1];
} WIN_TEXT;

static WIN_TEXT win_text;
static char *line = "Hello World";

void
main(void)
{
  WIN_TEXT *text;
  char *s,*d;
  int i;

  text = &win_text;
  if ( text->count<WIN_MAXTEXT ) {
    d = text->lines[text->count++];
    s = line;
    for ( i=0 ; *s && i<WIN_TEXTLEN ; i++ )
      *(d++) = *(s++);
    *d = '\0';
  }
}

When the line of code *(d++) = *(s++); is executed the value of the pointer "text" is also incremented.
If I make *s and *d global variables then the problem does not occur.

Can anyone tell me what I am doing wrong?

Regards
Paul

0