Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct node
- {
- unsigned char type;
- union
- {
- struct {
- char name[21];
- int id;
- } description;
- struct {
- double price;
- int amount;
- } stock;
- } product;
- struct node *next;
- } Node;
- typedef Node *Nodeptr;
- Nodeptr L;
- void insert(char *cname, int id, double price, int amount)
- {
- Nodeptr n;
- n = (Node *) malloc(sizeof(Node *));
- n->next = L;
- n->type = 's';
- strcpy(n->product.description.name, cname);
- n->product.description.id = id;
- L=n;
- }
- void printlist(Nodeptr L)
- {
- while (L!=NULL){
- printf("%s %d \n", L->product.description.name, L->product.description.id);
- L = L->next;
- }
- }
- int main()
- {
- FILE *f;
- L = NULL;
- f = fopen("date.in", "r");
- int n,i;
- int id, amount;
- char cname[21];
- double price;
- fscanf(f,"%d", &n);
- for(i=0; i<n; i++)
- {
- fscanf(f, "%s %d %f %d", cname, &id, &price, &amount);
- insert(cname, id, price, amount);
- }
- printlist(L);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement