Question: I haven't done any C programming for over a year and i'm completely lost. The code in the image was just the template we were

 I haven't done any C programming for over a year and

I haven't done any C programming for over a year and i'm completely lost. The code in the image was just the template we were given. The background info we were given is: " C's builtin types have a limited range of values, e.g. a typical int can hold values in the range 231-1 .. -231. Occasionally it would be useful to be able to manipulate much larger numbers. The aim for this lab is to start implementing a data type BigNum which can deal with such numbers.

To make it feasible to implement in a lab class, the BigNum data type has a very simple (and inefficient) structure. Each BigNum has an array of char values, where each char should be a decimal digit ('0'..'9')."

Exercise You are required to complete the implementation of the BigNum so that the add program works as expected. Specifically, you need to provide implementations for the following functions vold in?tBigNum(Bignum *n, int Nbytes) Initialise a BigNum object by seting the byte counter and by creating (malloc'ing) an array of length Nbytes. Use an assert() to check whether the array was successfully created. No return value void addBigNums (BigNum n, BigNum m, BigNum res) Add the values in n and m and store the result in res. If res is not initially large enough to hold the result, increase its size. No retun value. Note that this function (and all the others a3 well) use the convention that if the function only reads a struct parameter, then it's passed by value. However, if the intention of the function is to change the value of the struct, then it is passed by reference (i.e. using a pointer) int scanBigNum(char *s, BigNum n) Convert a string into a BigNum. Ignores any leading space characters in the string. If the first non-space is a digit, then scan to a non-digit (or end of string) and note where the last digit occurs. Then scan the digit-rich region of the string i.e. a contiguous sequence of digits) and place them in the appropriate location in the Bignum's array. If the string does not contain a sequence of digits after the spaces, then return O; otherwise return 1 void shonBigNum(BigNum n) Display the contents of a BigNum on standard output. Ignore leading 0' digits and then display all digits to the (lower) end of the array. If there are no non-0. cigits in the array, then print a single B. Do not print any other characters except the digits. No return value We recommend that you implement the functions in the following order: initBigNum(), showBigNum() (possibly inserting some data manually into the digits array), scanBigNum), addBigNums ). Altogether, it will require around 50 lines of C code. Once the program is workin g, you should be able to do thinga like: $.fadd 1080090000 42 Sun of 1888000880 and 42 is 1008800842 ./add 987654321987654321987654321 98765987659876598765 Sun of 987654321987654321987654321 and 987659B7659876598765 is 9876544287536419 18642539 6 #include 4 #include stdio.h #include ?#include string.h> #include 9 typedef unsigned char Byte; 1 typedef struet big num t 12 int nbytes size of array 13 Byte 'bytes array of Bytes 14BigNum; 6 Initialise a BigNum to N bytes, all zero 7 void initBigNum BigNum n, int Nbytes): 197 Add two BigNums and store result in a third BigNum 22 23 Set the value of a BigNum from a string of digits Returns 1 if it was a string of digits, 0 otherwise 4 int scanBigNum(char s, BigNum n) 26 / Display a Bigvum in decimat format 7 void showBigNum (BigNum n); 29 int nainlint argc, char argv]) 33 Initialise a BigNum to N bytes, all zero 4 void initBigNum(BigNum n, int Nbytes) /TODO return; 39// Add two BigNums and store result in a third Bi e void addBigNums (BigNum n, BigNum m, BigNum res) /TO00 return; 45 // Set the value of a Bigum from a string of digits 46 // Returns 1 if it *was* a string of digits, ? otherwise 47 int scanBigNum(char s, BigNun n) TODO return 1; 52 Display a BigWum in decinal foruat /TODO return

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!