The code uses a struct ( int x,y) to print message when c->x increase the value by 1, but unlike c->x , ptr1 pointer "forgets" its address.
How can I create a pointer to string array without "forgetting" its address?
#include <stdio.h>
#define msgROW 5
#define msgLEN 16
struct cursxy{
unsigned int x;
unsigned int y;
};
void cursor(struct cursxy *c,char (*ptr1)[msgLEN])
{
c->x++;
printf("%s \n", *ptr1++);
}
int main()
{
struct cursxy cursxy = {0,0};
char messages[msgROW][msgLEN] =
{
"Set Duty Cycle",
"Set Frequency",
"Set Hours",
"Set Minutes",
"Set Current"
};
char (*ptrMsg)[msgLEN] = messages;
//c->x = 1 , prints first message
cursor(&cursxy,ptrMsg); //ptrMsg point to first message
//c->x = 2 , prints again the first message
cursor(&cursxy,ptrMsg); //ptrMsg Didn't point to second message <------------
// and so on
}