|
That suggests that you have not initialised the object. Have you checked that the constructor is called and sets all the variables correctly?
|
|
|
|
|
It does not look like you are reading the string, you are actually assigning values. It seems the exception is from somewhere else.. Is this the complete code you are debugging ?? Could you please share the full code if possible ?
|
|
|
|
|
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.
|
|
|
|
|
It's really rather difficult to figure out what you are trying to do since some of the above code makes no real sense. You are using casts on pointers that are already pointers, so do nothing except add confusion. You allocate a block of memory and then try to print it before it contains anything. You create an array of ponters for no apparent reason and then use only the first one, you copy data from one memory block to another, again for no real reason, etc. Maybe you should show exactly what problem you are trying to solve, without all this code and we can advise on the best option. And an explanation of what the print function actually does, or is supposed to do.
Also please use <pre> and </pre> tags around your code so it is more readable, like this:
lcd_i2c.clear();
lcd_i2c.print("Index ");
lcd_i2c.print(i);
lcd_i2c.setCursor(0, 1);
|
|
|
|
|
Well, you can easily look at the data-sheet for the I2C chip on the LCD board and at the one for the 1602/1604/2002/2004 LCD you're using. Once done, you can see that the LCD has a hardware cursor, and knows at which position on the display it is. It also has a means to write a character to the current cursor position.
Here's a quick list of the available commands: http://www.8051projects.net/lcd-interfacing/commands.php[^]
Not covered in that particular document, is the fact that you define custom bitmaps for characters - up to 4 or so at any one time. You could for instance, make a bitmap of a battery and then animate a charging display by changing the bitmap used for the battery 'character'.(but not actually changing the character drawn - it's the bitmap that this character refers to that is changed)
Here's a tool I whipped-up a couple of years back that makes drawing such custom characters easy. I've used this for both ascii/graphical LCDs - I don't remember if the output was suitable for both or just one or the other.
Lcd Character designer The 'save' button causes the changes made to a character in the top-pane to be written to the 'memory' of the LCD panel and causes the appearance of the currently chosen character to change.
As for the pointer stuff, you seem to be making it considerably more complex than it needs to be.
Here's a quick sample. I dont have access to an arduino this moment, so have used printf instead.
int main()
{
char *stringTable[] = { "string 1", "string two", "string three", NULL };
int i, n = sizeof(stringTable) / sizeof(*stringTable);
for (i=0; i<n-1; i++)
printf("(%d chars): %s\n", strlen(stringTable[i]), stringTable[i]);
printf("-------------\n");
char **curPtr = stringTable;
do
{
printf("%s\n", *curPtr); curPtr++; } while ( *curPtr ); }
"When I was 5 years old, my mother always told me that happiness was the key to life. When I went to school, they asked me what I wanted to be when I grew up. I wrote down 'happy'. They told me I didn't understand the assignment, and I told them they didn't understand life." - John Lennon
|
|
|
|
|
Thanks,
basically you confirmed that I need a pointer to the double dimension array.
That is all I wanted to know.
Cheers
Vaclav
|
|
|
|
|
Why are you using both a sentinel value and the array size (just out of curiosity)?
|
|
|
|
|
Simply to show two ways of doing the same thing. Vaclav's code expects a sentinel, while I prefer to work without one.
"When I was 5 years old, my mother always told me that happiness was the key to life. When I went to school, they asked me what I wanted to be when I grew up. I wrote down 'happy'. They told me I didn't understand the assignment, and I told them they didn't understand life." - John Lennon
|
|
|
|
|
Ok I think I am getting the picture.
But I cannot figure out how to implement same pointer arithmetic in double array.
I got the first "record" working fine, can access all strings / fields, but cannot get to the next one.
I am still not sure how does the pointer , and not the char in array , get incremented.
I have deleted the LCD code which confused many and added printf , which is not part of "core" Arduino code , so this should pass by them now.
I still would like some verbal description of the assignment of pointer to the array.
Appreciate your help very much.
Cheers
Vaclav
<pre lang="c++"> // double array of pointers
char *stringTable[][5] = {{ "string 1", "string two", "string three", NULL },
{ "second string 1", "second string two", "second string three", NULL }
};
char **curPtr = *stringTable; // pointer to array of pointers
do
{
printf("%s\n", *curPtr++); // dereference to get the ptr to the string
} while ( *curPtr ); // quit loop when we get to our NULL pointer.<pre lang="c++"><pre lang="c++"></pre></pre></pre>
|
|
|
|
|
No problem, it's one of the problems that seems to beat-up people regularly. I more or less started with ASM, so it was a matter of sink or swim in short order.
How about this, does it help?
int main()
{
char *stringTable[][4] = {
{ "string 1", "string two", "string three", NULL },
{ "second string 1", "second string two", "second string three", NULL }
};
int y;
for (y=0; y<sizeof(stringTable)/sizeof(stringTable[0]); y++) {
char **curPtr = stringTable[y];
do
{
printf("%s\n", *curPtr++);
} while (*curPtr);
printf("----\n");
}
}
"When I was 5 years old, my mother always told me that happiness was the key to life. When I went to school, they asked me what I wanted to be when I grew up. I wrote down 'happy'. They told me I didn't understand the assignment, and I told them they didn't understand life." - John Lennon
|
|
|
|
|
Thanks,
problem solved.
Actually while "programming in my sleep" I thought that I must be missing advancing the "main" pointer by the whole record. But stringTable[y] is nice "trick".
I really appreciate your help and as soon as I figure out how to add the characters into the record ( one at a time ) I'll be all set.
You have a great day.
Cheers
Vaclav
PS When I get ambitious I will try to figure out how to replace stringTable[y] using pointer.
|
|
|
|
|
Vaclav_Sal wrote: 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". I use a 4x20 LCD display on my Arduino Uno and Mega boards. What are you trying to do?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Try asking one question at a time. If I have to spend 30 minutes trying to figure out what you're really getting at, I'm not too inclined to help. Help us help you. Keep the questions straightforward.
Jeremy Falcon
|
|
|
|
|
I am not sure what the readers problems are - my English or their inability to read.
I do not like to engage in this kind of non technical discussions, have better things to do.
But since you asked
I said I can figure out the LCD "problem" - so I really don't understand why I am getting all the flack for mentioning it. I was trying to avoid " what are you trying to do?".
So again , I have NO Problem with LCD , it is just a convenient way to track my code.
And if it includes stuff you feel is weird so what. It has NOTHING to do with my MAIN question.
And the question is in the title of this post.
So far only ONE reply has given me REAL answer.
I have been around here for a while and in past EVERYBODY was 100% courteous and very helpful.
I am occasionally participating in Arduino forum where majority of "gurus" are nowhere near of caliber of knowledge as this forum is.
They commonly switch subject, give lectures on OT , hamper on "post you full code", "what you doing?" , scrutinize coding style (if it does not lineup with their style) etc. Very egotistical and unfriendly bunch, especially to beginners.
<b><b><b></b></b>I am rather sadden to see that similar attitude is showing up on this forum.</b>
I am sorry I got on my soap box, but if you have no idea you are doing / posting in style not in line with this forum traditions and guidelines you should be told so.
So that what I did.
Please no more off the tech subject stuff.
Cheers and have a nice one.
Vaclav
|
|
|
|
|
You have the wrong attitude.
Jeremy Falcon
|
|
|
|
|
Vaclav_Sal wrote: I am not sure what the readers problems are - my English or their inability to read. Neither, it's the fact that you question is rather over complicated, without actually explaining what the problem is. Hence my original reply to your question, which you ignored.
|
|
|
|
|
Hello everyone,
I have a weird situation...I have a CToolBar that has a parent of a CPagerCtrl which has a parent of a CDockingPane. Why I developed it that was is a long story and changing the architecture is not really an option at this point. Everything is working quite well except for one problem behavior. And this wouldn't have been a problem had the requirements not changed.
The problem behavior is that initially the toolbar has 9 buttons, but before it is shown I remove some of them depending on the options enabled. Depending on the state of the application at a particular time I may add buttons back. The toolbar does not reflect the change. In the past I would have just called RecalcLayout() on the frame window and voila, the toolbar would adjust it's size to properly reflect the new buttons.
I am at a loss on how to accomplish this with this architecture. I have tried many things...so many I can't remember them right now. Any ideas/help would be greatly appreciated. I will post any code upon request. I am just not sure what is of value right now.
Thanks,
Craig
|
|
|
|
|
I aim to build a network system like router or firewall based on customized embedded Linux. about the memory and stack, I will use embedded appliance like ARM boards or Atom not a simple Micro-controller or processor. which lang. you advice me to use C or C++? . I will use YOCTO Project to help me do that.
I built a similar network system.it was a network IDS but, it was based on xPC Target Kernel. Now, I wish to use an Embedded Linux. the system must do the basic task, so no many options. I have an experience in C and C++ but under DOS not Linux. C++ has the many options make the system design is easier but I fare the compatibility if I used it in embedded Linux. So any advice?
|
|
|
|
|
Abdullah A._Mohamed wrote: C++ has the many options make the system design is easier but I fare the compatibility if I used it in embedded Linux. So any advice?
I bet on C++ : Linux usually provides g++ that is a very good C++ compiler.
By the way, could you please delete your duplicate post?
|
|
|
|
|
CPallini wrote: By the way, could you please delete your duplicate post?
It's not just a duplicate post - he's created two accounts as well!
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Wait, maybe we have a replicant! 
|
|
|
|
|
thank you Pallini, its not a duplicated but I am a new here and I login using my other accounts like face and g+ So, it seems two accounts is made and I put the Q on the two accounts. sorry.
modified 24-Jul-15 1:25am.
|
|
|
|
|
Oh, that is no problem at all, for me.
You are welcome. 
|
|
|
|
|
Abdullah A._Mohamed wrote: I fare the compatibility if I used it in embedded Linux
C++ is used pretty extensively in embedded Linux.
This is more of a matter of preference, you should be able to easily find supporting libraries for both, but I'd imagine that you'd find quite a bit more for C++... so that may be the easiest route.
|
|
|
|
|
Albert Holguin, thank you, I hope that.
|
|
|
|
|