Hi,
Below part code for 16x2 LCD,
------------------
void send_string(const char *s) //send a string to display in the lcd
{
while (s && *s)send_char (*s++);
}
---------------------
void send_char(unsigned char data) //send lcd character
{
..loop
}
----------------------
I trying to understand how the code //while (s && *s)send_char (*s++); is executed ?? if the argument is passed like "ABCD" ????
I only known the statement in c that //while(), but what is the meaning of that while()with the passing argument by calling function ..ie, //while (s && *s)send_char (*s++);
could you please clear anybody. and can you share a link whare such statement is exist please.
tnx
"while (s && *s)send_char (*s++);"
This statement simply says that send characters until you find identifier to terminate, to form a string. here the identifier is null pointer, it means when all characters are displayed then it stops execution until it gets next character. it is the another example of character declaration similar to
char p[4] = "four";
or char *s = "four";
above both declarations will work same except that s++ is valid but p++ is not valid.
also in,
char p[4] = "four";
The "four" is stored in stack section of memory.
where as in,
char *s = "four";
The 's' is stored in stack but "four" is stored in code section of memory.
Also,
"while (s && *s)send_char (*s++);"
and
"while (s && *s){
send_char (*s++);"
}
both statement are valid in C.
If there is one statement after condition then you can write a function just ahead of condition.
e.g:
if(a=b) a++;
or if (a=b){
a++;
}
{
while (s && *s)send_char (*s++);
}
If '&&' is logical-AND and '*s' is "not-s" then the logic
is "never" and nothing happens.
No you are wrong...
'*s' is not "not-s" . *s indicates a pointer variable. not s will be represent by "!s"
Abhimanyu Pandit
Permalinkit would be easy to understand and explain it to if you can send the whole code with declaration of 's'
- Log in or register to post comments
Joined January 21, 2019 42Monday at 12:12 PM