Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct tree
- {
- char* nume;
- struct tree* parinte;
- }tree;
- typedef struct tree* Tree;
- Tree init(char* nume)
- {
- tree* t;
- t = (Tree) malloc(sizeof(struct tree));
- t->nume = strdup(nume);
- t->parinte = NULL;
- return t;
- }
- int main()
- {
- FILE *f1, *f2;
- int i, nr, nr_Q, dif;
- char *copil, *parinte, *comanda, *a1, *a2;
- Tree arbore;
- f1 = fopen("data.in", "r");
- f2 = fopen("data.out", "w");
- copil = (char *) malloc(50);
- parinte = (char *) malloc(50);
- comanda = (char *) malloc(10);
- a1 = (char *) malloc(50);
- a2 = (char *) malloc(50);
- fscanf(f1, "%d", &nr);
- arbore = (Tree) malloc(nr*sizeof(struct tree));
- for (i=0;i<nr;i++)
- {
- fscanf(f1, "%s %s\n", copil, parinte);
- arbore[i].nume = strdup(copil);
- arbore[i].parinte = init(parinte);
- }
- fscanf(f1, "%d", &nr_Q);
- fclose(f1);
- fclose(f2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment