Advertisement
cd62131

max of bids

Apr 5th, 2019
714
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.56 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int main(void) {
  4.   FILE *in = fopen("bids.txt", "r");
  5.   if (!in) {
  6.     exit(1);
  7.   }
  8.   int max = 0;
  9.   for (char buf[BUFSIZ]; fgets(buf, BUFSIZ, in);) {
  10.     int bid;
  11.     if (sscanf(buf, "%*s%d", &bid) == 1) {
  12.       if (max < bid) {
  13.         max = bid;
  14.       }
  15.     }
  16.   }
  17.   rewind(in);
  18.   for (char buf[BUFSIZ]; fgets(buf, BUFSIZ, in);) {
  19.     char name[BUFSIZ];
  20.     int bid;
  21.     if (sscanf(buf, "%s%d", name, &bid) == 2) {
  22.       if (bid == max) {
  23.         printf("%s\n", name);
  24.       }
  25.     }
  26.   }
  27.   fclose(in);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement