Click here to Skip to main content
15,902,492 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Passing an "array" in C Pin
CPallini1-Aug-15 5:55
mveCPallini1-Aug-15 5:55 
QuestionC++ Service Crash in Windows Server 2008 R2 Machine Pin
janaswamy uday29-Jul-15 7:26
janaswamy uday29-Jul-15 7:26 
QuestionRe: C++ Service Crash in Windows Server 2008 R2 Machine Pin
Richard MacCutchan29-Jul-15 21:10
mveRichard MacCutchan29-Jul-15 21:10 
GeneralWho has the type of remote control code, can you give me a copy? Pin
HackLee27-Jul-15 16:20
HackLee27-Jul-15 16:20 
GeneralRe: Who has the type of remote control code, can you give me a copy? Pin
enhzflep27-Jul-15 18:19
enhzflep27-Jul-15 18:19 
GeneralRe: Who has the type of remote control code, can you give me a copy? Pin
HackLee27-Jul-15 19:42
HackLee27-Jul-15 19:42 
GeneralRe: Who has the type of remote control code, can you give me a copy? Pin
HackLee27-Jul-15 19:41
HackLee27-Jul-15 19:41 
QuestionError reading characters of string Pin
Django_Untaken27-Jul-15 9:19
Django_Untaken27-Jul-15 9:19 
AnswerRe: Error reading characters of string Pin
Richard Andrew x6427-Jul-15 9:54
professionalRichard Andrew x6427-Jul-15 9:54 
GeneralRe: Error reading characters of string Pin
Django_Untaken27-Jul-15 18:06
Django_Untaken27-Jul-15 18:06 
AnswerRe: Error reading characters of string Pin
Richard Andrew x6427-Jul-15 18:21
professionalRichard Andrew x6427-Jul-15 18:21 
GeneralRe: Error reading characters of string Pin
Django_Untaken27-Jul-15 18:32
Django_Untaken27-Jul-15 18:32 
AnswerRe: Error reading characters of string Pin
Richard Andrew x6427-Jul-15 18:58
professionalRichard Andrew x6427-Jul-15 18:58 
AnswerRe: Error reading characters of string Pin
Albert Holguin28-Jul-15 6:23
professionalAlbert Holguin28-Jul-15 6:23 
QuestionRe: Error reading characters of string Pin
Richard MacCutchan27-Jul-15 21:02
mveRichard MacCutchan27-Jul-15 21:02 
AnswerRe: Error reading characters of string Pin
Django_Untaken28-Jul-15 6:26
Django_Untaken28-Jul-15 6:26 
GeneralRe: Error reading characters of string Pin
Richard MacCutchan28-Jul-15 6:34
mveRichard MacCutchan28-Jul-15 6:34 
GeneralRe: Error reading characters of string Pin
SundararamanS28-Jul-15 23:39
SundararamanS28-Jul-15 23:39 
QuestionAccessing / printing two dimensional array of char using pointers Pin
Vaclav_26-Jul-15 4:06
Vaclav_26-Jul-15 4:06 
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.
Cheers
Vaclav


Addendum
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[0];
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.clear();
lcd_i2c.print("Index ");
lcd_i2c.print(i);
lcd_i2c.setCursor(0, 1);

lcd_i2c.print("Length ");
lcd_i2c.print(ncharacters );

lcd_i2c.setCursor(0, 2);
lcd_i2c.print("pointer ");
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[0] = sptr;
lcd_i2c.setCursor(0, 3);
i = 0;
do
{
// TOK prints first character from stringTable[0]
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.
AnswerRe: Accessing / printing two dimensional array of char using pointers Pin
Richard MacCutchan26-Jul-15 5:51
mveRichard MacCutchan26-Jul-15 5:51 
AnswerRe: Accessing / printing two dimensional array of char using pointers Pin
enhzflep26-Jul-15 6:47
enhzflep26-Jul-15 6:47 
GeneralRe: Accessing / printing two dimensional array of char using pointers Pin
Vaclav_26-Jul-15 7:35
Vaclav_26-Jul-15 7:35 
QuestionRe: Accessing / printing two dimensional array of char using pointers Pin
CPallini26-Jul-15 20:49
mveCPallini26-Jul-15 20:49 
AnswerRe: Accessing / printing two dimensional array of char using pointers Pin
enhzflep27-Jul-15 0:54
enhzflep27-Jul-15 0:54 
GeneralRe: Accessing / printing two dimensional array of char using pointers Pin
Vaclav_27-Jul-15 15:23
Vaclav_27-Jul-15 15:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.