Here is the FINAL version. ; )
Code:
int *fchar(char buf[], FILE *stream, size_t size)
{
int i = 0;
while ((buf[i++] = fgetc(stream)) != EOF && i < size -1)
;;
while (buf[i--] != '\n')
;;
buf[i] = '\0';
return 0;
}
Called:
Code:
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include "/Source/str.h"
int main(int *argc, char *argv[])
{
char buf[1024];
int i = 0;
FILE *file;
if (!argv[1]) {
fprintf(stdout, "Usage: File as first arg...\n");
return 1;
}
if ((file = fopen(argv[1], "r")) == NULL) {
fprintf(stderr, "fopen: Failed.\n");
exit(1);
}
fchar(buf, file, sizeof(buf));
fprintf(stdout, "%s\n", buf);
return 0;
}
In case anyone wants to play with it. ; )
{edit}
Changed it, I didn't notice anything strange.