Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I got feedback from my professor about my code I turned in and he said this about it: You are not initializing or using your

I got feedback from my professor about my code I turned in and he said this about it:

You are not initializing or using your array; you just made a bunch of singletons to dodge the array notation.

Can someone provide me with the right answer to this problem and why what I did was wrong?

Overview

In this assignment, the student will write a program collects individual character bytes in an array and displays a variety of resolved values from those characters.

When completing this assignment, the student should demonstrate mastery of the following concepts:

Individual Character Input with scanf()

Phantom Characters and Correction Techniques

Character Arrays

Address-of Operator (&)

Output Formatting with printf()

Assignment:

Write a program that declares an array capable of holding five characters. Initialize the array to hold blank spaces upon creation (ASCII value 3210). Prompt the user to enter 5 characters in a series of prompts with scanf() and the conversion character %c. Intentionally cause phantom characters to enter the keyboard buffer when initially coding your solution, but later demonstrate both correction techniques (absorbing the enter key AND rewind(stdin)) within your solution on different prompts. Your final submission should have the phantoms being addressed in some way everywhere corruption can potentially occur. Read the keystrokes into a character array and use that array to display the base-10 ASCII code, the character symbol, and the address of each character byte on the call stack in base-16. Keep in mind that more recent versions of the compiler will issue an error when using scanf() due do deprecation.

Here is the code I submitted:

#pragma warning(disable:4996)

#include

#include

int main() {

// Initialize with empty spaces...

char keystroke1;

char keystroke2;

char keystroke3;

char keystroke4;

char keystroke5;

char charArray[5];

char absorbPhantom;

printf("Please enter a character and press enter: ");

scanf("%c%c", &keystroke1, &absorbPhantom);

printf("The ASCII code for that is: %d ", &keystroke1);

printf("Please enter a character and press enter: ");

scanf("%c%c", &keystroke2, &absorbPhantom);

printf("The ASCII code for that is: %d ", &keystroke2);

printf("Please enter a character and press enter: ");

scanf("%c", &keystroke3);

rewind(stdin);

printf("The ASCII code for that is: %d ", &keystroke3);

printf("Please enter a character and press enter: ");

scanf("%c", &keystroke4);

rewind(stdin);

printf("The ASCII code for that is: %d/ ", &keystroke4);

printf("Please enter a character and press enter: ");

scanf("%c", &keystroke5);

printf("The ASCII code for that is: %d ", &keystroke5);

// Get the characters from the user.

printf("CHAR | ASCII | ADDRESS ");

printf(" %-4c | %-2d | %-7x ", &keystroke1, &keystroke1, &keystroke1);

printf(" %-4c | %-2d | %-7x ", &keystroke2, &keystroke2, &keystroke2);

printf(" %-4c | %-2d | %-7x ", &keystroke3, &keystroke3, &keystroke3);

printf(" %-4c | %-2d | %-7x ", &keystroke4, &keystroke4, &keystroke4);

printf(" %-4c | %-2d | %-7x ", &keystroke5, &keystroke5, &keystroke5);

// Display the information table.

_getch();

return 0;

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 14th East European Conference Adbis 2010 Novi Sad Serbia September 2010 Proceedings Lncs 6295

Authors: Barbara Catania ,Mirjana Ivanovic ,Bernhard Thalheim

2010th Edition

3642155758, 978-3642155758

Students also viewed these Databases questions