Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with a C programming problem (will rate highly): C CODE (COPY/PASTE): /*-------------------------------------------------------------------------* *--- ---* *--- byDigitAdder.c ---* *--- ---* *--- This file defines

Need help with a C programming problem (will rate highly):

image text in transcribed image text in transcribed

C CODE (COPY/PASTE):

/*-------------------------------------------------------------------------* *--- ---* *--- byDigitAdder.c ---* *--- ---* *--- This file defines a C program that represents positive ---* *--- decimal integers as linked lists of digits. It asks the user ---* *--- for 2 integers, computes the sum, and outputs it. ---* *--- ---* *--- ---- ---- ---- ---- ---- ---- ---- ---- ---* *--- ---* *--- Version 1a 2018 February 11 Joseph Phillips ---* *--- ---* *-------------------------------------------------------------------------*/ #include  #include  #include  #define NUM_TEXT_LEN 256 // PURPOSE: To represent one digit of a decimal number. struct DigitNode { int digit_; // I suggest you range this in [0..9] struct DigitNode* nextPtr_; // I suggest you make this point to // the next most significant digit. }; // PURPOSE: To obtain the text of a decimal integer into array 'numberCPtr' // of length 'numberTextLen'. 'descriptionCPtr' is printed because it // tells the user the integer that is expected. Ending ' ' from // 'fgets()' is replaced with '\0'. No return value. void obtainPostiveInt(char* numberCPtr, int numberTextLen, const char* descriptionCPtr ) { // YOUR CODE HERE } // PURPOSE: To build and return a linked list IN LITTLE ENDIAN ORDER // of the decimal number whose text is pointed to by 'numberCPtr'. // If 'numberCPtr' points to the string "123" then the linked list // returned is 'digit_=3' -> 'digit_=2' -> 'digit_=1' -> NULL. struct DigitNode* numberList (const char* numberCPtr ) { // YOUR CODE HERE } // PURPOSE: To build and return a linked list IN LITTLE ENDIAN ORDER // of the decimal number that results from adding the decimal numbers // whose digits are pointed to by 'list0' and 'list1'. struct DigitNode* add (const struct DigitNode* list0, const struct DigitNode* list1 ) { // YOUR CODE HERE } // PURPOSE: To print the decimal number whose digits are pointed to by 'list'. // Note that the digits are IN LITTLE ENDIAN ORDER. No return value. void printList (const struct DigitNode* list ) { // YOUR CODE HERE } // PURPOSE: To print the nodes of 'list'. No return value. void freeList (struct DigitNode* list ) { // YOUR CODE HERE } // PURPOSE: To coordinate the running of the program. Ignores command line // arguments. Returns 'EXIT_SUCCESS' to OS. int main () { char numberText0[NUM_TEXT_LEN]; char numberText1[NUM_TEXT_LEN]; struct DigitNode* operand0List = NULL; struct DigitNode* operand1List = NULL; struct DigitNode* sumList = NULL; obtainPostiveInt(numberText0,NUM_TEXT_LEN,"first"); obtainPostiveInt(numberText1,NUM_TEXT_LEN,"second"); operand0List = numberList(numberText0); operand1List = numberList(numberText1); sumList = add(operand0List,operand1List); printList(operand0List); printf(" + "); printList(operand1List); printf(" = "); printList(sumList); printf(" "); freeList(sumList); freeList(operand1List); freeList(operand0List); return(EXIT_SUCCESS); } 
Safe C memory programming The program below represents decimal integers as a linked list of digits. It asks for 2 positive integers, stores them as linked lists, computes the sum, and outputs it. It then freeO's all nodes of all 3 lists. a. You must use my struct Digi tNode b. I strongly suggest that you represent the integers in little-endian order. That will make add 0) way easier. Please write: obtainPostiveInt numberList () o add printList o freeList Sample output: (No surprises here, it is just decimal integer addition, but these are some interesting boundary cases to make sure you handle.)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

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

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions