• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

how print pointer to a string on LCD

Not open for further replies.


New Member
Hello friends

how can in print pointer to a string on LCD

char a[] = "Hello world";
char *ptr2 = a; // Points to the 'H' of "Hello world"

how can print *ptr2

codevisionAVR Atmega64 , alcd.h

Daniel Wood

Strings are generally null terminated.

Stick it in a while loop with the expression: while(*ptr2 != 0)
print out each character at a time and then increment the pointer, inside the loop. A bit like:
printf("%c", *ptr2++);

Daniel Wood

Might I add, your string must end with a null character (0 in decimal) with the above technique, otherwise you will end up printing data from other areas of memory.

Another (likely safer) way is to have an integer variable called a_length, with the number of characters specified explicitly.

Then you print and increment the pointer inside a "for" loop until all the characters have been iterated.
Not open for further replies.

Latest threads

EE World Online Articles