The pointer variable
s actually contains an address, which contains a character value.
Therefore, when
s is dereferenced using the
* operator the character value is return instead of the address value.
Pointers can be a challenging topic for many people to understand, review the following tutorials and then post any additional questions:
A TUTORIAL ON POINTERS AND ARRAYS IN C
C - Pointers
Lesson 6: Pointers in C
BigDog
- - - Updated - - -
Code:
lcd_dataa(unsigned char *disp) // function to send string to LCD
{
int x;
for(x=0;disp[x]!=0;x++)
{
lcd_data(disp[x]);
}
}
The
lcd_dataa() routine performs a similar function as the previous
display_lcd(), the main difference is the character string is incremental accessed using array index methods rather than the pointer methods.
The pointer of type character
disp when combined with the square index brackets [], essentially provides an array of type character by which each element of the array can be accessed by incrementing or decrementing the index.
Each time index
x is incremented in the
for loop, the contents of the array element
disp[x] is checked for a NULL or value 0x00, just as was done using the pointer methods.
If the current element of the character array
disp is not NULL, it is passed to the lcd_data() routine.
Essentially, the lcd_dataa() incrementally steps through each element of the character array disp and passes these characters to the lcd_data() routine, until the NULL is encounter which terminates the routine.
Initially, before the char pointer is incremented:
*s == s[0] o r *disp == disp[0]
BigDog