Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <errno.h>
- #include <inttypes.h>
- #include <stdint.h>
- #include <stdio.h>
- #include <stdlib.h>
- static uint32_t count(FILE *in) {
- uint32_t c = 0;
- for (;;) {
- errno = 0;
- int x;
- int ret = fscanf(in, "%d", &x);
- if (ret == EOF || !ret || errno) {
- break;
- }
- ++c;
- }
- return c;
- }
- int main(void) {
- FILE *in = fopen("data1.txt", "r");
- if(!in) {
- exit(1);
- }
- uint32_t c = count(in);
- fclose(in);
- printf("%"PRIu32"\n", c);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement