Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define N 20
- typedef char *String;
- typedef struct{
- int size;
- int count;
- String *content;
- } *Elenco;
- int main( void ) {
- int size = 4, i = 0;
- char name[N+1] = "";
- Elenco b = malloc( sizeof(Elenco) );
- b -> size = 4;
- b -> count = 0;
- b -> content = calloc( size, sizeof(char *) );
- while( strcmp( name, "FINE" ) != 0 ) {
- scanf( "%s", name );
- b->count++; //aumento b->count se no non entrerà mai nel if
- if ( b -> count == b -> size ) {
- b-> size *= 2;
- b-> content = realloc (b-> content, b->size * sizeof(char *)); //b->size al posto di size, se no è sempre 44
- }
- b->content[i]=calloc(N+1,sizeof(char));
- b->content[i]=strcpy(b->content[i],name);
- i++;
- }
- for ( int k = 0; k < b -> count-1; k++ ) //count no size
- printf( "%s\n", b -> content[k] );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement