Back to Programming Languages forum
How can I use a while loop to create an array of the charcters for each line?
On the other hand you really need not array ;-)
Here are two choices:
fgetc
to read input character-by-character (really with while
) and updating counters at the same time - you then need reset counters and print current result each time you encounter '\n'
which is the sign of line end (this approach is widely covered in Kernighan & Ritchie book);or you should prepare empty array and read the whole line into it with gets
or fgets
:
char line[1000];
gets(line); // now it contains next line, zero-terminated
P.S. I'm afraid that I may forgot many C
-related tricks so if my suggestions are not good enough you may want to ask questions
at C-gurus forum.
> This thread should move in the languages subforum (and be renamed)?
Done! At last I've implemented functionality for moving/renaming posts for myself :)