C / C++ / MFC
|I am still struggling with pointers arithmetic.
Here is my crude test code.
I want to use pointers to access ( double - need triple eventually) the array of characters and do not get two things.
Problem #1 is probably how does the LCD class do the "print" and I can figure that one by myself. I do not expect this forum to be familiar with Arduino "library".
Problem # 2
I can print single characters in simple array by incrementing the pointer, but I cannot figure out why I cannot use same method on double array.
I really do not understand what is this error telling me
"error lvalue required as increment operand" - what is "lvalue" ?
Please keep in mind that English is not my native language so go easy on
" pointers to array..." "array of pointers" etc.
As always , I appreciate your help.
OK, I did some more reading about how the array is initialized and how the NAME of the array cannot be used the way I did try it.
So I did this - it "works" , but I am still not sure if it is correct or just a fluke.
char *pointer = stringTable;
lcd_i2c.print((char*) pointer++); // prints entire line
lcd_i2c.print((char*) pointer); // prints entire line starting with second character - expected that
Original post code starts here
char line[MAX_LINE] = "A TEST B";
int ncharacters = strlen(line);
char *sptr; // pointer to memory block returned by malloc
char *stringTable[NLINES]; // array of pointers to string
int i = 0;
sptr = (char*) malloc((unsigned) strlen(line) + 1);
lcd_i2c.print(sptr); // problem #1 prints the entire line - not really a problem here
strcpy(sptr, line); // copy line to pointed memory
lcd_i2c.print(sptr); // TOK prints pointer value ?
// copy pointer to first table array
stringTable = sptr;
i = 0;
// TOK prints first character from stringTable
lcd_i2c.print((char) * (*stringTable)); // problem #1 prints only the first character - why it would be nice to print the entire line using pointers!
} while (*(*++stringTable)); error lvalue required as increment operand
-- modified 26-Jul-15 11:18am.
General News Suggestion Question Bug Answer Joke Praise Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.