daily pastebin goal
77%
SHARE
TWEET

Untitled

a guest Feb 13th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct  _pioci{
  5.   char name[100];
  6.   float mil;
  7.   struct _pioci * next;
  8. } pioci;
  9.  
  10.  
  11.  
  12. void main(){
  13.   FILE *pfile;
  14.  
  15.   struct _pioci * HEAD = malloc(sizeof(pioci));
  16.   struct _pioci * TAIL = malloc(sizeof(pioci));
  17.   HEAD->next=NULL;
  18.   TAIL->next=NULL;
  19.  
  20.   // char fname[100];
  21.   // scanf("%s", fname);
  22.   if(!(pfile = fopen("ExamText.txt", "r"))) return;
  23.  
  24.   fscanf(pfile, "%s %f %*s",HEAD->name,&HEAD->mil);
  25.  
  26.   while(fscanf(pfile,"%s %f %*s\n",TAIL->name,&TAIL->mil)==2){ //da errore, legge solo la prima riga
  27.     struct _pioci * temp = HEAD;
  28.     int condition = 0;
  29.     while(temp){
  30.       if(temp->name==TAIL->name){
  31.         temp->mil += TAIL->mil;
  32.         condition = 1;
  33.       }
  34.       temp=temp->next;
  35.     }
  36.     if(!condition){
  37.       temp=TAIL;
  38.     }
  39.     TAIL=malloc(sizeof(pioci));
  40.     fscanf(pfile,"\n");
  41.   }
  42.   while(HEAD){
  43.     printf("Nome: %s\tPioggia (ml):\n",HEAD->name,HEAD->mil);
  44.     HEAD=HEAD->next;
  45.   }
  46.   return;
  47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top