Advertisement
Alx09

10.5

May 8th, 2022
1,001
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.15 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. typedef struct Cuvant{
  6.     char text[16];         
  7.     struct Cuvant *pred;
  8.     struct Cuvant *urm;
  9.     }Cuvant;
  10.  
  11. Cuvant *Cuvant_nou(const char *text)
  12. {
  13.     Cuvant *c=(Cuvant*)malloc(sizeof(Cuvant));
  14.     if(!c){
  15.         printf("memorie insuficienta");
  16.         exit(EXIT_FAILURE);
  17.         }
  18.     strcpy(c->text,text);
  19.     return c;
  20. }
  21.  
  22. #define LISTAD_NUME         Propozitie          // numele TDA
  23. #define LISTAD_ELEMENT   Cuvant         // tipul unui element din lista
  24. #include "listad.h"
  25.  
  26. Cuvant *Propozitie_cauta(Propozitie *p,const char *text)
  27. {
  28.     Cuvant *c;
  29.     for(c=p->prim;c;c=c->urm){
  30.         if(!strcmp(c->text,text))return c;
  31.         }
  32.     return NULL;
  33. }
  34.  
  35. int main(int argc, char* argv[])
  36. {
  37.     Propozitie p;
  38.     int op;     // optiune
  39.     char text[16];
  40.     Cuvant *c;
  41.  
  42.     Propozitie_init(&p);
  43.     FILE *f;
  44.     f =  fopen(argv[1], "r");
  45.      while(fscanf(f,"[^\n]%s", text) != EOF){
  46.            
  47.                  Propozitie_adauga(&p, Cuvant_nou(text));
  48.      }          
  49.           for(c=p.prim;c;c=c->urm)printf("%s\n",c->text);
  50.        
  51.     return 0;
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement