Please answer the following questions in C program 3 a Write
Please answer the following questions in C program.
3. a. Write a program that stores the string \"Hooray for All of Us\" in an array named strng. Use the declaration char string [] = \"Hooray for All of Us\";, which ensures that the end-of-string escape sequence \\0 is included in the array. Display the characters in the array by changing the address in a pointer called messPtr. Use a for statement in your program.
b. Modify the program written in 3a to use the while statement while (*messPtr ! \'\\0\').
c. Modify the program written in 3a to start the display with the word All.
Solution
The code of all the three parts in c language are given below-
a-
#include <stdio.h>
#include <string.h>
int main() {
int i,length;
char strng[50] ={\'H\', \'o\', \'o\', \'r\', \'a\', \'y\', \'f\', \'o\', \'r\', \'A\', \'l\', \'l\', \'o\', \'f\', \'U\', \'s\', \'\\0\'};
char *messPtr = strng;
length = strlen(strng);
for (i=0; i<length; i++)
{
printf(\"%c\", *messPtr);
messPtr++;
}
return 0;
}
b-
#include <stdio.h>
#include <string.h>
int main() {
int i,length;
char strng[50] ={\'H\', \'o\', \'o\', \'r\', \'a\', \'y\', \'f\', \'o\', \'r\', \'A\', \'l\', \'l\', \'o\', \'f\', \'U\', \'s\', \'\\0\'};
char *messPtr = strng;
length = strlen(strng);
messPtr= messPtr+9;
while (*messPtr!= \'\\0\')
{
printf(\"%c\", *messPtr);
messPtr++;
}
return 0;
}
c-
#include <stdio.h>
#include <string.h>
int main() {
int i,length;
char strng[50] ={\'H\', \'o\', \'o\', \'r\', \'a\', \'y\', \'f\', \'o\', \'r\', \'A\', \'l\', \'l\', \'o\', \'f\', \'U\', \'s\', \'\\0\'};
char *messPtr = strng;
length = strlen(strng);
messPtr= messPtr+9;
for (i=0; i<length; i++)
{
printf(\"%c\", *messPtr);
messPtr++;
}
return 0;
}

