c - Can I get fscanf to not skip over empty lines? -
i'm trying programme read input file not skip on empty lines fscanf typically does. file , loop scan file is:
infile = fopen("text.txt", "r"); for(i = 0; fscanf(infile, "%s", &input[i]) != eof; i++){ printf("%d %s\n", i, input[i]); }
which outputs:
0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 twelve 12 13 13 14 14 15 15 16 16 seventeen 17 18 18 19 19 20 20 30 21 40 22 50 23 60 24 70 25 80 26 90
which isn't want. want text beingness read represent position in array says. ie "ninety" found @ input[89].
and file beingness read is:
one 2 3 4 5 6 7 8 9 10 11 twelve 13 14 15 16 seventeen 18 19 20 30 40 50 60 70 80 90
each of words supposed represent line it's beingness read from. i'm adding space between 20+ lines, can utilize represent line of info beingness read in. in short, i'm making number text generator read
999.99
as
nine hundred ninety-nine , 99/100
tl;dr don't want hard code position in array contains word, i'm trying create iterator work, , needs blank lines read take position in array.
any way can create fscanf job here? or should utilize else?
thank you
i think you'd improve off using fgets()
. if necessary, can utilize sscanf()
on resulting string parse it.
edit - this:
infile = fopen("text.txt", "r"); size_t = 0; while (fgets(input[i], line_size, infile)) { printf("%d %s\n", i, input[i]); ++i; }
c fscanf file-io
No comments:
Post a Comment