• 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

Thread starter #1
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
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++);
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.

Latest threads

EE World Online Articles