Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct el
- {
- char info;
- struct el *next;
- };
- typedef struct el *t_lista;
- t_lista riempiLista(FILE *fp)
- {
- t_lista first, attuale;
- char carattere;
- fscanf(fp, "%c", &carattere);
- first = malloc(sizeof(struct el));
- first->info = carattere;
- first->next = attuale;
- while(!feof(fp))
- {
- fscanf(fp, "%c", &carattere);
- attuale = malloc(sizeof(struct el));
- attuale->info = carattere;
- attuale->next = NULL;
- attuale = attuale->next;
- }
- attuale->next = NULL;
- return first;
- }
- int verificaLista(t_lista testa)
- {
- int countTonda = 0, countQuadra = 0, countGraffa = 0;
- t_lista temp = testa;
- while(temp != NULL)
- {
- if(temp->info == '(')
- countTonda++;
- if(temp->info == ')')
- countTonda--;
- if(temp->info == '[')
- countQuadra++;
- if(temp->info == ']')
- countQuadra--;
- if(temp->info == '{')
- countGraffa++;
- if(temp->info == '}')
- countGraffa--;
- temp = temp->next;
- }
- if(countTonda != 0 || countQuadra != 0 || countGraffa != 0)
- {
- printf("Errore, almeno una stringa non e' ben parentesizzata\n");
- return -1;
- }
- else
- {
- printf("Il file e' ben parentesizzato");
- return 0;
- }
- }
- int main()
- {
- FILE *fp;
- t_lista testa;
- fp = fopen("dati.txt", "r");
- if(fp == NULL)
- {
- printf("Errore nell'apertura del file\n");
- return -1;
- }
- else
- {
- testa = riempiLista(fp);
- verificaLista(testa);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement