box-o-sand/ex24_iofunctions02.c

31 lines
731 B
C

#include <stdio.h>
#include "dbg.h"
int main(int argc, char *argv[])
{
int a, b, rc;
char c;
char filename[1024 * 2];
FILE *fp;
printf("Provide filename from which to inputs\n> ");
rc = fscanf(stdin, "%s", filename);
check(rc == 1, "Failed to read filename");
fp = fopen(filename, "r");
check(fp != NULL, "Failed to open file %s", filename);
printf("Reading from file: <a:number> <b:number> <c:letter>\n");
rc = fscanf(fp, "%d %d %c", &a, &b, &c);
check(rc == 3, "Failed to read from \"%s\".", filename);
printf("Read in: a=%d b=%d c=%c\n", a, b, c);
rc = fclose(fp);
check(rc != EOF, "Failed to close file \"%s\"", filename);
return 0;
error:
return 1;
}