Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct _pioci{
- char name[100];
- float mil;
- struct _pioci * next;
- } pioci;
- void main(){
- FILE *pfile;
- struct _pioci * HEAD = malloc(sizeof(pioci));
- struct _pioci * TAIL = malloc(sizeof(pioci));
- HEAD->next=NULL;
- TAIL->next=NULL;
- // char fname[100];
- // scanf("%s", fname);
- if(!(pfile = fopen("ExamText.txt", "r"))) return;
- fscanf(pfile, "%s %f %*s",HEAD->name,&HEAD->mil);
- while(fscanf(pfile,"%s %f %*s\n",TAIL->name,&TAIL->mil)==2){ //da errore, legge solo la prima riga
- struct _pioci * temp = HEAD;
- int condition = 0;
- while(temp){
- if(temp->name==TAIL->name){
- temp->mil += TAIL->mil;
- condition = 1;
- }
- temp=temp->next;
- }
- if(!condition){
- temp=TAIL;
- }
- TAIL=malloc(sizeof(pioci));
- fscanf(pfile,"\n");
- }
- while(HEAD){
- printf("Nome: %s\tPioggia (ml):\n",HEAD->name,HEAD->mil);
- HEAD=HEAD->next;
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement