how print pointer to a string on LCD

Status
Not open for further replies.

Azadfalah

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
 
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.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…