typeprint/c/typeprint.c

38 lines
672 B
C
Raw Normal View History

#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
2015-06-07 17:09:03 -04:00
static int process(char *name);
2015-06-07 04:54:52 -04:00
static int
2015-06-07 17:09:03 -04:00
process(char *name)
{
2015-06-07 04:10:23 -04:00
FILE *file = fopen(name, "r");
2015-06-07 17:09:03 -04:00
struct timespec ts;
ts.tv_sec = 0;
ts.tv_nsec = 10 * 1000000;
if (file == 0) {
fprintf(stderr, "[err] no such file or directory\n");
return ENOENT;
2015-06-07 04:10:23 -04:00
}
2015-06-07 04:10:23 -04:00
int x;
while ((x = fgetc(file)) != EOF) {
2015-06-07 04:54:52 -04:00
printf("%c", x);
fflush(stdout);
2015-06-07 17:09:03 -04:00
nanosleep(&ts, NULL);
2015-06-07 04:10:23 -04:00
}
fclose(file);
2015-06-07 04:10:23 -04:00
return 0;
}
int
main(int argc, char *argv[])
{
return process(argv[1]);
2015-06-07 17:09:03 -04:00
}