Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main(void)
- {
- //int count = 0;
- //char c;
- int numArray[100]; // holds day1.txt elements
- int i; // file
- int total = 0;
- FILE *fp = fopen("day1.txt","r");
- for (int j = 0; j < 100; j++)
- {
- if (fscanf(fp, "%d", &i) == 1) // fscanf goes through file until EOF, and assign read value to variable &i
- {
- numArray[j] = i;
- numArray[j] = floor(numArray[j] / 3);
- numArray[j] = numArray[j] - 2;
- total += numArray[j];
- }
- }
- printf("%d\n", total);
- /***
- for(c = getc(fp); c != EOF; c = getc(fp)) // count # of lines in file and print
- {
- if (c == '\n')
- count = count + 1;
- }
- printf("There are %i lines", count);
- ***/
- fclose(fp);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement