Question: #include #include #include /** * The given program is to display ASCII code and binary of user entered character. * Run and test with characters

#include #include #include /** * The given program is to display ASCII code and binary of user entered character. * Run and test with characters in the extended ASCII table, such as , , , , etc. * and you'll see that some ASCII codes displayed by the program are INCORRECT * Your job is to fix the program so that it can display correct ASCII code * for character entered by user. * Submit a screenshot of * > source code on one side, showing the repeatition loop in the main method, and * > output on the other side, with tests of character 1, a, , and  */ void getBinary(int arr[], int number, int numOfBits); void printArray(int arr[], int numberOfElements); void clearBuffer(); int main(void) { //declare a unionNumber, of type union myUnionType int size = sizeof(int) * 8; int arr[size]; char testChar; int testInt; //Repeatition loop while(1 == 1){ //get user input puts("Please enter a character:"); scanf("%c", &testChar); //test with  clearBuffer(); if(testChar == 'q')// if q: terminate the program break; testInt = testChar;//directly assign to int //Display information printf("You enter character '%c', ", testChar); printf("ASCII code: %d ", testChar);//Fix this //Display binary printf("Binary of int: \t"); getBinary(arr, testInt, size); printArray(arr, size); printf("Binary of char: "); getBinary(arr, testChar, sizeof(char) * 8); printArray(arr, sizeof(char) * 8); puts("-------------------------------------------------"); } return EXIT_SUCCESS; } void clearBuffer(){ char c; while((c = getchar()) != ' '); } /*getBinary - get the binary representation of number into the array arr. Arguments: arr - the integer array to hold the binary representation number - the integer to get binary from numOfBits - the size of the arr and the number of bits for the binary Algorithm requirement: make use of bitwise shifting and masking to get the bit values for the number */ void getBinary(int arr[], int number, int numOfBits){ int i = numOfBits - 1; for(; i >= 0; i --){ arr[i] = number & 01; //Apply mask 01 to keep only the lowest 1 bit (i.e., the right-most bit), and store the result to the array number = number >> 1; //Right-shift 1 bit } } /* printArray: print numberOfElements in the argument integer array */ void printArray(int arr[], int numberOfElements){ int i = 0; for(; i < numberOfElements; i ++){ printf("%d", arr[i]); } puts("");//new line }

* The given program is to display ASCII code and binary of user entered character.

* Run and test with characters in the extended ASCII table, such as , , , , etc.

* and you'll see that some ASCII codes displayed by the program are INCORRECT

* Your job is to fix the program so that it can display correct ASCII code for character entered by user.

* Submit a screenshot of

* > source code on one side, showing the repeatition loop in the main method, and

* > output on the other side, with tests of character 1, a, , and

IN C

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!