Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- typedef struct record record;
- struct record {
- char name[32];
- float score;
- };
- typedef struct node node;
- struct node {
- record data;
- node *next;
- };
- int main() {
- char data[100];
- char name[32];
- float x;
- node *p, *head;
- int counter = 0;
- head = 0;
- while ((fgets(data, 60, stdin) != NULL) && counter <= 3) {
- p = (node *) malloc (sizeof(node));
- sscanf(data, "%s %f", name, &x);
- strcpy(p->data.name,name);
- p->data.score = x;
- p->next = head;
- head = p;
- counter++;
- }
- printf("-----------------------n");
- while (p) {
- printf("%s %fn",p->data.name, p->data.score);
- p = p->next ;
- }
- return 0;
- }
- //input
- bob 10
- shiela 5
- john 1
- elisa 10
- //print input
- elisa 10.000000
- john 1.000000
- shiela 5.000000
- bob 10.000000
- p->next = head;
- head = p;
- head -> null
- head -> A -> null
- head -> B -> A -> null
- head -> C -> B -> A -> null
- p->next = null; // new node will always be end of list
- if (head == NULL) // special trap for empty list
- head = p; // means set up head
- else // otherwise
- tail->next = p; // current tail now points to new node
- tail = p; // make new node the tail for next time
Add Comment
Please, Sign In to add comment