Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Programming Language Expert

Long interger linked list add function

Posting I am working on program assignment in structures (c language)after entering the required intergers the add function will not compile.I receive error messages I am using a Microsoft c, c++ 6.0 compiler. The help required is to provide a working add function in c. Hopefully after that I will be be able to write similar functions to subtract multiply and divide.

The given problem requires that an add function be provided that should add two given lists n and m.

The source code of the problem is attached

#include
#include
#include

typedef struct node
{
int data; // char field data
struct node* next; //pointer field next
}NODE,*NODEP,**NODEPP; //defines three common types

// Function prototypes

void addhead(NODEPP listp,int value);

void getinput1( NODEPP );

void getinput2( NODEPP );
void showtext ( char* );
void showlist( char*,NODEP);
void add_list( listp );
void add();
void subtract();
void multiply();
void divide();
void main (void)
{

char cmd;

showtext(" Enter a to add, s to subtract, m to multiply , d to divide,q when finished");
for (;;)
{
scanf("%c",&cmd);

switch(cmd)
{
case 'a': add(); //addition

break;
case 's': subtract(); // subtract
break;
case 'm':multiply(); //multiply
break;
case 'd':divide(); //divide
break;
case 'q':
exit(0);
break;
}
showtext("nEND OF RUNn");
}

}// end of main

// Adds new node at the heaad of the list. puts value in the data field

void addhead(NODEPP listp, int value)
{

NODEP p = (NODEP)malloc( sizeof (NODE));
p->data = value; // Data Field gets value
p->next = *listp; // links p node to old head
*listp = p; // makes p a new head node
}

void getinput1( NODEPP listp ) //creats a linked list containing numbers
{ // entered by the user.(uses add_to_list)

int n;

printf("Enter a series of integers (! when finished ):");

while((scanf("%d",&n))==1)

addhead(listp,n); //Add new node to list

}

void getinput2( NODEPP listp) //creats a linked list containing numbers
{ // entered by the user.(uses add_to_list)

int m;

printf("Enter a second series of integers (! when finished ):");

while((scanf("%d",&m))==1)

addhead(listp,m); //Add new node to list

}

void showtext ( char* string ) //Displays text
{

printf(string);

}

void showlist(char* string, NODEP list) // Prints list to screen
{

int i =1;
showtext(string);
while (list !=NULL)
{
printf( "%5d",list->data);
if(i++% 10 ==0)showtext("n");
list =list->next;
}
showtext("n END OF LISTn");

}

void add(NODEPP listp ) //add function
{
NODEP n= NULL;
NODEP m =NULL;
NODEP t= NULL;

int tPtr;
tPtr=&t;
showtext( "**INITIAL LIST DATA**n");

getinput1( &n);
showlist("List 1n",n);
getchar();

getinput2( &m);
showlist("List 2n",m);

getchar();

while(t!=0)
{
t->data= n->data+m->data;
}

showlist( "The sum of List 1 and List 2 is:n",t);
}
void subtract(NODEPP listp)

{

}

void multiply()
{

}

void divide()
{

}

Programming Language, Programming

  • Category:- Programming Language
  • Reference No.:- M91619348
  • Price:- $20

Priced at Now at $20, Verified Solution

Have any Question?


Related Questions in Programming Language

Question - create a microsoft word macro using vba visual

Question - Create a Microsoft Word macro using VBA (Visual Basic for Applications). Name the macro "highlight." The macro should highlight every third line of text in a document. (Imagine creating highlighting that will ...

Assignmentquestion onegiving the following code snippet

Assignment Question One Giving the following code snippet. What kind of errors you will get and how can you correct it. A. public class HelloJava { public static void main(String args[]) { int x=10; int y=2; System.out.p ...

Task - hand execution of arraysoverviewin this task you

Task - Hand Execution of Arrays Overview In this task you will demonstrate how arrays work by hand executing a number of small code snippets. Instructions Watch the Hand Execution with Arrays video, this shows how to ste ...

Task silly name testeroverviewcontrol flow allows us to

Task: Silly Name Tester Overview Control flow allows us to alter the order in which our programs execute. Building on our knowledge of variables, we can now use control flow to create programs that perform more than just ...

Assignment - proposal literature review research method1

Assignment - Proposal, Literature Review, Research Method 1. Abstract - Summary of the knowledge gap: problems of the existing research - Aim of the research, summary of what this project is to achieve - Summary of the a ...

Assignment task -q1 a the fibonacci numbers are the numbers

Assignment Task - Q1. (a) The Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and are characterised by the fact that every number after the first two is the sum of the ...

Structs and enumsoverviewin this task you will create a

Structs and Enums Overview In this task you will create a knight database to help Camelot keep track of all of their knights. Instructions Lets get started. 1. What the topic 5 videos, these will guide you through buildi ...

Php amp session managment assignment -this assignment looks

PHP & SESSION MANAGMENT ASSIGNMENT - This assignment looks at using PHP for creating cookies and session management. Class Exercise - Web Project: Member Registration/Login This exercise will cover adding data connectivi ...

Assignment - haskell program for regular expression

Assignment - Haskell Program for Regular Expression Matching Your assignment is to modify the slowgrep.hs Haskell program presented in class and the online notes, according to the instructions below. You may carry out th ...

Question 1 what is a computer program what is structured

Question: 1. What is a Computer program? What is structured programming? 2. What is modular programming? Why we use it? 3. Please evaluate Sin (x) by infinite series. Then write an algorithm to implement it with up to th ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As