Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.07 KB | None | 0 0
  1. int main(void)
  2. {
  3.  
  4.         //int count = 0;
  5.         //char c;
  6.         int numArray[100]; // holds day1.txt elements
  7.         int i; // file
  8.         int total = 0;
  9.  
  10.  
  11.         FILE *fp = fopen("day1.txt","r");
  12.  
  13.         for (int j = 0; j < 100; j++)
  14.         {
  15.                 if (fscanf(fp, "%d", &i) == 1) // fscanf goes through file until EOF, and assign read value to variable &i
  16.                 {
  17.                         numArray[j] = i;
  18.  
  19.                         numArray[j] = floor(numArray[j] / 3);
  20.  
  21.                         numArray[j] = numArray[j] - 2;
  22.  
  23.                         total += numArray[j];
  24.                 }
  25.                        
  26.                
  27.                
  28.         }
  29.        
  30.  
  31.         printf("%d\n", total);
  32.        
  33.        
  34.         /***
  35.         for(c = getc(fp); c != EOF; c = getc(fp))        // count # of lines in file and print
  36.         {
  37.                 if (c == '\n')
  38.                         count = count + 1;
  39.         }
  40.         printf("There are %i lines", count);
  41.         ***/
  42.  
  43.  
  44.  
  45.         fclose(fp);
  46.  
  47.         return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement