mihainan

Tema - Raluca

Apr 24th, 2014
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.91 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. typedef struct tree
  6. {
  7.     char* nume;
  8.     struct tree* parinte;
  9. }tree;
  10.  
  11. typedef struct tree* Tree;
  12.  
  13. Tree init(char* nume)
  14. {
  15.     tree* t;
  16.     t = (Tree) malloc(sizeof(struct tree));
  17.     t->nume = strdup(nume);
  18.     t->parinte = NULL;
  19.     return t;
  20. }
  21.  
  22. int main()
  23. {
  24.     FILE *f1, *f2;
  25.     int i, nr, nr_Q, dif;
  26.     char *copil, *parinte, *comanda, *a1, *a2;
  27.     Tree arbore;
  28.     f1 = fopen("data.in", "r");
  29.     f2 = fopen("data.out", "w");
  30.     copil = (char *) malloc(50);
  31.     parinte = (char *) malloc(50);
  32.     comanda = (char *) malloc(10);
  33.     a1 = (char *) malloc(50);
  34.     a2 = (char *) malloc(50);
  35.     fscanf(f1, "%d", &nr);
  36.     arbore = (Tree) malloc(nr*sizeof(struct tree));
  37.     for (i=0;i<nr;i++)
  38.     {
  39.         fscanf(f1, "%s %s\n", copil, parinte);
  40.         arbore[i].nume = strdup(copil);
  41.         arbore[i].parinte = init(parinte);
  42.     }
  43.     fscanf(f1, "%d", &nr_Q);
  44.     fclose(f1);
  45.     fclose(f2);
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment