I'm stuck on this. Currently I'm using:
FILE *a = fopen("sample.txt", "r");
int n;
while ((n = fgetc(a)) != EOF) {
putchar(n);
}
However this method seems to be a bit inefficient. Is there any better way? I tried using fgets:
char *s;
fgets(s, 600, a);
puts(s);
There's one thing I find wrong about this second method, which is that you would need a really large number for the second argument of fgets.
Thanks for all the suggestions. I found a way (someone on IRC told me this) using open(), read(), and write().
char *filename = "sample.txt";
char buf[8192];
int r = -1;
int in = open(filename, O_RDONLY), out = 0;
if (in == -1)
return -1;
while (1) {
r = read(in, buf, sizeof(buf));
if (r == -1 || r == 0) { break; }
r = write(out, buf, r);
if (r == -1 || r == 0) { break; }
}