kbhitvoid will examine the RDA status bit and return a true

kbhit(void): – will examine the RDA status bit and return a true (non-zero value) if RDA is true, otherwise it will return a false (0 value).

getchar(void): – will read one character from the serial port and return it.

putchar(char vname): – write the character vname to the serial port when TBE is true.

Function to write a string:

printstr(*unsigned char str0)

{

int i=0;

while (str0[i] != 0x00) // while NOT NULL

{

    putchar(str0[i]); // send char

    i++;

}

}

I do not understand this line of code, which is while (str0[i] != 0x00). Why I need to test if str0[i]==0?

Solution


printstr(*unsigned char str0)
{
int i=0;
while (str0[i] != 0x00) // while NOT NULL
{
putchar(str0[i]); // send char
i++;
}
}
I do not understand this line of code, which is while (str0[i] != 0x00). Why I need to test if str0[i]==0?
The printstr() is a method which will take a character pointer as input, and will print the string of characters
pointed to by str0. And the loop condition str0[i] != 0x00 is used to check if the end of string is reached or not.
And the loop will check for the end of string. And if it\'s not end of string, the character is printed.

0x00 is a sentinel character in the string. And the characters will be printed repeatedly till the sentinel character is reached.

kbhit(void): – will examine the RDA status bit and return a true (non-zero value) if RDA is true, otherwise it will return a false (0 value). getchar(void): – w

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site