Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that will write a sentence using constant character arrays and p

ID: 3632702 • Letter: W

Question

Write a program that will write a sentence using constant character arrays and pointer arithmetic. For this assignment you will use only the following two variable declarations:

const char upLetters[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};

const char loLetters[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', ' ', '.', ' '};

The only other statements that should be in your program should be the return statement and calls to the putchar() function. This function accepts one parameter, a character (or the integer value that corresponds to an integer). Use pointer arithmetic with the array names to offset to the character that you would like to print.

Print the sentence “My name is Drew.”, with your name replacing mine.

Explanation / Answer

#include void main () { const char upLetters[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}; const char loLetters[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', ' ', '.', ' '}; //"My name is " is printed by the following statements. putchar (*(upLetters+12)); // M putchar (*(loLetters+24)); // y putchar (*(loLetters+26)); //' ' putchar (*(loLetters+13)); // n putchar (*(loLetters+0)); // a putchar (*(loLetters+12)); // m putchar (*(loLetters+4)); // e putchar (*(loLetters+26)); //' ' putchar (*(loLetters+8)); // i putchar (*(loLetters+18)); // s putchar (*(loLetters+26)); //' ' //to print your name start with a uppercase_letter+offset and then rest of the name from lowercase_letter+offset. putchar (*(upLetters+3)); // D putchar (*(loLetters+17)); // r putchar (*(loLetters+4)); // e putchar (*(loLetters+22)); // w //to print '.' and new line putchar (*(loLetters+27)); //'.' putchar (*(loLetters+28)); // return; }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote