Advertisement
qqbre

Day 1 Part 1, 2018, C

Dec 9th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.52 KB | None | 0 0
  1. #include <stdio.h>
  2. int main(int argc, char *argv[])
  3. {
  4.     int freq = 0;
  5.     char text[256];
  6.     int sum = 0;
  7.     FILE *day1;
  8.     if ((day1 = fopen("day1.txt", "r")) == NULL) {
  9.         puts("File could not be found/opened");
  10.     }
  11.     else {
  12.         puts("Opened, processing...");
  13.         while (!feof(day1)) {
  14.            fscanf(day1, "%256s", text);
  15.            freq = atoi(text);
  16.            sum = sum + freq;
  17.         }
  18.         printf("Sum of all freq is:%d ", sum);
  19.         fclose(day1);
  20.     }
  21.     return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement