Bob said:
Is there any way to read a single at a time in
from file I have a file with
variable length strings with diffrent amounts of words on each line.
If the situation is one where you have a known maximum line length
then you can do it this way:
#define LINE_LEN 63
#define str(x) # x
#define xstr(x) str(x)
int rc;
char array[LINE_LEN + 1];
FILE *fd ;
char *fn = "file.txt";
fd = fopen(fn, "r");
if (fd == NULL) {
fprintf(stderr, "\nfopen() problem with \"%s\"\n", fn);
exit(EXIT_FAILURE);
}
rc = fscanf(fd, "%" xstr(LINE_LEN) "[^\n]%*[^\n]", line);
if (!feof(fd)) {
getc(fd);
}
If rc equals 1, then a line has been converted to a string in array.
If the file line has more than LENGTH bytes,
the extra ones are discarded.
If rc equals 0, there was only a newline character in the file line
and no conversion was done.
If rc equals EOF, you've reached the end of the file.No conversion.