malloc()
# Include <ctype. h>
# Include <stdlib. h>
Struct bignum
{
Char dig;
Struct bignum * next;
}
* LIST;
Void my_malloc (LIST *);
Void output (LIST );
LIST add (LIST, LIST );
Void my_free (LIST );
Void move (LIST *);
Int get_dig (LIST );
Void put (int, LIST *);
{
LIST p_num1, p_num2;
LIST p_sum;
Puts ("enter an integer :");
P_num1 = get_num ();
Puts ("enter an integer :");
P_num2 = get_num ();
Output (p_sum );
Putchar ('\ n ');
My_free (p_sum );
My_free (p_num1 );
My_free (p_num2 );
Return 0;
}
{
If (* p = malloc (sizeof (** p) = NULL)
Exit (1 );
}
LIST get_num (void)
{
LIST p = NULL;
Int c;
While (c = getchar () & isdigit (c ))
{
LIST tmp;
My_malloc (& tmp );
Tmp-> dig = c-'0 ';
Tmp-> next = p;
P = tmp;
}
Return p;
}
{
If (p-> next! = NULL)
Free (p-> next );
}
{
If (p = NULL)
Return 0;
Return p-> dig;
}
{
If (* pp = NULL)
Return;
* Pp = (* pp)-> next;
}
{
My_malloc (pp );
(* Pp)-> dig = n;
(* Pp)-> next = NULL;
}
{
LIST p_res = NULL;
LIST * pp_res = & p_res;
Char low, high = 0;
While (p1! = NULL | p2! = NULL)
{
Low = high; // high is the carry of the previous time
Low + = get_dig (p1) + get_dig (p2 );
High = low/10; // write down carry
Low % = 10;
Put (low, pp_res); // Add and
Pp_res = & (* pp_res)-> next;
Move (& p1), move (& p2 );
}
If (high! = 0) // process the carry of the highest bit
Put (high, pp_res );
}
Void output (LIST p)
{
If (p-> next! = NULL)
Output (p-> next );
Putchar (p-> dig + '0 ');
}