Exemple #1
0
int main(void) {
   Run r[20];
   int numRuns = readRunsFromFile(r, "run.data");
   char loop;
   
   displayRuns(r, numRuns);
	
   printf("(a)dd run or (q)uit: ");
   scanf("%c", &loop);

   if(loop == 'q') printf("\n");

   while(loop != 'q') {
      printf("\n");
		
      if (loop == 'a') numRuns = addRun(r, numRuns);

      printf("\n");
      displayRuns(r, numRuns);
	   
      printf("(a)dd run or (q)uit: ");
      scanf(" %c", &loop);
      printf("\n");
	
   }
	
   writeFile(r, numRuns);
   
   printf("Happy trails!\n");

   return 0;
}
Exemple #2
0
int main(void)
{
   Run r[MAX_RUNS];
   int numRuns;
   
   numRuns = readFile(r);
   displayRuns(r, numRuns);
   addRun(r, numRuns);
   printf("\nHappy trails!\n");

   return 0;
}
Exemple #3
0
void addRun(Run r[], int numRuns)
{
   char answer, name[20];
   int index, h, m, s, totalSecs;

   printf("(a)dd run or (q)uit: ");
   scanf(" %c", &answer);
   while(answer == 'a')
   {
      printf("\nRun Name: ");
      scanf("%s", name);      
      findRun(r, numRuns, name, &index);
     
      if(index == -1)
      {
         numRuns += 1;
         strcpy(r[numRuns - 1].name, name);
         
         printf("Distance in Miles: ");
         scanf("%lf", &r[numRuns - 1].distance);
         printf("Time (hh mm ss): ");
         scanf("%2d %2d %2d", &h, &m, &s);

         totalSecs = s + m * SECS_PER_MIN + h * SECS_PER_HOUR;
         r[numRuns - 1].prSec = totalSecs;
         r[numRuns - 1].count = 1;
      }
      else
      {
         printf("Time (hh mm ss): ");
         scanf("%2d %2d %2d", &h, &m, &s);

         totalSecs = s + m * SECS_PER_MIN + h * SECS_PER_HOUR;
         if(totalSecs < r[index].prSec)
         {
            r[index].prSec = totalSecs;
         }
         r[index].count += 1;
      }
      
      displayRuns(r, numRuns);
      printf("(a)dd run or (q)uit: ");
      scanf(" %c", &answer);
   }
  writeFile(r, numRuns);
  return;   
}