Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #define N 20
  6.  
  7. typedef char *String;
  8. typedef struct{
  9. int size;
  10. int count;
  11. String *content;
  12. } *Elenco;
  13.  
  14.  
  15. int main( void ) {
  16. int size = 4, i = 0;
  17. char name[N+1] = "";
  18.  
  19. Elenco b = malloc( sizeof(Elenco) );
  20. b -> size = 4;
  21. b -> count = 0;
  22. b -> content = calloc( size, sizeof(char *) );
  23.  
  24. while( strcmp( name, "FINE" ) != 0 ) {
  25. scanf( "%s", name );
  26. b->count++; //aumento b->count se no non entrerà mai nel if
  27. if ( b -> count == b -> size ) {
  28. b-> size *= 2;
  29. b-> content = realloc (b-> content, b->size * sizeof(char *)); //b->size al posto di size, se no è sempre 44
  30. }
  31.  
  32. b->content[i]=calloc(N+1,sizeof(char));
  33. b->content[i]=strcpy(b->content[i],name);
  34. i++;
  35.  
  36. }
  37.  
  38. for ( int k = 0; k < b -> count-1; k++ ) //count no size
  39. printf( "%s\n", b -> content[k] );
  40.  
  41. return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement