Question

q7.3 Fix the errors in the code (in C) //This program uses a function called CharacterScan...

q7.3 Fix the errors in the code (in C)

//This program uses a function called CharacterScan to read a char from the user

//The function must take an int pointer as a parameter

//The program should print the char and ascii code for each character the user enters

//The program should only exit whe nthe user enters escape

#include <stdio.h>

char CharacterScan(int*);

int main(void){

while(1){

int aCode;

int* iPtr;

char* c = CharacterScan(iPtr);

if(aCode)

break;

else

printf("%c is ASCII code %d.\n", c, iPtr);

}

}

char CharacterScan(int iPtr){

char c;

printf("Enter a character: ");

scanf(" %c", &c);

iPtr = &c;

return &c;

}

Homework Answers

Answer #1

`Hey,

Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

//This program uses a function called CharacterScan to read a char from the user

//The function must take an int pointer as a parameter

//The program should print the char and ascii code for each character the user enters

//The program should only exit whe nthe user enters escape

#include <stdio.h>

char CharacterScan(int*);

int main(void){

while(1){


int iPtr;

char c = CharacterScan(&iPtr);
int aCode=iPtr;

if(!aCode)
break;
else
printf("%c is ASCII code %d.\n", c, iPtr);

}

}

char CharacterScan(int* iPtr){

char c;

printf("Enter a character: ");

scanf(" %c", &c);

*iPtr = (int)c;
return c;

}

Kindly revert for any queries

Thanks.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
I am to create three different versions of the following C program code below that implements...
I am to create three different versions of the following C program code below that implements the conversion of unsigned binary numbers into decimal (Base 2 to Base 10 conversion). Version 1: Complete the C program ”bin2dec ver1.c” that implements binary to decimal conversion. The maximum number of binary bits is 32. The program is made of the functions ”unsigned binary to decimal(const char *str)”and ”main”. The parameter ”str” passed to this function points to a C string comprising only...
debug code on C(not C+ or C++) I try to fix by myself, node part show...
debug code on C(not C+ or C++) I try to fix by myself, node part show error. This program should work for scan 5 ints from the user Using those 5 ints, it require construct a linked list of 5 elements. After this, it sould prntf of the list using the PrintList. #include <stdio.h> struct Node{    int data;    Node* next; }; int main(void){    struct Node first = {0, 0};    struct Node* second = {0, 0};   ...
Using the following code answer the next couple questions: #include<stdio.h> #include<stdlib.h> #include<string.h> /* Rewrite using a...
Using the following code answer the next couple questions: #include<stdio.h> #include<stdlib.h> #include<string.h> /* Rewrite using a pointer to char str[] */ void array_to_ptr () { int n=0, len; char str[ ] = "Hello World!"; len = strlen(str); for( n=0; n<len; n++) {     putc(str[n], stdout); } printf("\nlength = %d\n", n); } int contains (char * str, char c); int * makearray(int n); int main (void) { printf("Question #2 - array_to_ptr:\n"); array_to_ptr();   printf("\n------------------------------------\n\n"); printf("Question #3 - contains:\n"); printf("Test #1: "); if...
"C language" Take this code and make the minor modification necessary to create a circular linked...
"C language" Take this code and make the minor modification necessary to create a circular linked list (Hint: Store a pointer to the first node in the next pointer of the last node.) Demonstrate that this is working by traversing the list until the first pointer is encountered 3 times. Next redefine the node structure to include a back pointer. This will enable your program to move from front to back and then from back to front. It is not...
This is a debugging question. Please write comments where it is fixed. Thanks. q7.4 Fix the...
This is a debugging question. Please write comments where it is fixed. Thanks. q7.4 Fix the errors in the code (in C) //This program is supposed to scan 5 ints from the user //Using those 5 ints, it should construct a linked list of 5 elements //Then it prints the elements of the list using the PrintList function #include <stdio.h> struct Node{ int data; Node* next; }; int main(void){ struct Node first = {0, 0}; struct Node* second = {0,...
C - Language Write an expression that executes the loop while the user enters a number...
C - Language Write an expression that executes the loop while the user enters a number greater than or equal to 0. Note: These activities may test code with different test values. This activity will perform three tests, with user input of 9, 5, 2, -1, then with user input of 0, -17, then with user input of -1. Also note: If the submitted code has an infinite loop, the system will stop running the code after a few seconds,...
The following code should print X is greater than 0. However, the code has errors. Fix...
The following code should print X is greater than 0. However, the code has errors. Fix the code so that it compiles and runs correctly. (Rewrite the program with all the fixes) public class Test1 { public static void main(String[] args) { int x = 3; if (x > 0 System.out.println("x is greater than 0") else System.out.println(x is less than or equal 0"); } } Must be in java and easy to understand grade 11 course
The code is in C programming language pls convert it into python. Thanks. Program --> #include...
The code is in C programming language pls convert it into python. Thanks. Program --> #include <stdio.h> #include <stdlib.h> void main() { //declare variables FILE *fileptr; char filename[15]; char charRead; char filedata[200],searchString[50]; int i=0,j=0,countNoOfWord=0,count=0; //enter the filename to be opened printf("Enter the filename to be opened \n"); scanf("%s", filename); /* open the file for reading */ fileptr = fopen(filename, "r"); //check file exit if (fileptr == NULL) { printf("Cannot open file \n"); exit(0); } charRead = fgetc(fileptr); //read the string...
For the following code in C, I want a function that can find "america" from the...
For the following code in C, I want a function that can find "america" from the char array, and print "america is on the list" else "america is not on the list" (Is case sensitive). I also want a function to free the memory at the end of the program. #include <stdio.h> #include <stdlib.h> struct Node { void *data; struct Node *next; }; struct List { struct Node *head; }; static inline void initialize(struct List *list) { list->head = 0;...
Write a C/C++ program that performs the tasks described below. If there is just 1 command-line...
Write a C/C++ program that performs the tasks described below. If there is just 1 command-line argument and it is -hw you should simply print hello world and then exit(0). Otherwise, the program should provide a function named mm_alloc. This is the function prototype: void *mm_alloc(int num_bytes_to_allocate) mm_alloc function should obtain space for the user from a block which you obtain via mmap. You should obtain the block on the first invocation and the block size should be some number...