{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

c programming 3 - if(newaddr ==(struct MyList NULL Sheet1...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 struct MyList { char value[MAXCHARS] struct MyList *nextAddr } struct MyList *firstRec int main() { void datainput() void display() int i firstRec = NULL printf("\nEnter five values from the keyboard:\n") for(i=0 i<5 i++) { printf("Value #%d:",i+1) datainput() } display() printf("\nEnter another value to add to the list: ") datainput() display() system("pause") return 0 } void datainput() { char value[MAXCHARS] void insert(char *) gets(value) insert(value) } void insert(char *value) { struct MyList *newaddr, *here newaddr = (struct MyList *) malloc(sizeof(struct MyList))
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: if(newaddr == (struct MyList *) NULL) { Sheet1 Page 2 printf("\nCould not allocate the requested space\n") exit(1) } if(firstRec == NULL) { newaddr -> nextAddr = NULL firstRec = newaddr } else { newaddr -> nextAddr = firstRec firstRec = newaddr } strcpy(newaddr -> value,value) } void display() { struct MyList *contents contents = firstRec printf("\nThe values contained in your list are: \n") while (contents != NULL) { printf("%s\n", contents -> value) contents=contents -> nextAddr } }...
View Full Document

{[ snackBarMessage ]}

Page1 / 2

c programming 3 - if(newaddr ==(struct MyList NULL Sheet1...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon bookmark
Ask a homework question - tutors are online