4 answers
You can read like this ...
#include <stdio.h> int main() { char c; FILE *bu=fopen("input.txt","r"); int i=0; while (c!='\n') { fscanf(bu,"%c",&c); i++; } fclose(bu); return 0; }
But a lot depends on what is the end of the line ... The end may be, for example, the following combination # 13 # 10 (in hex), that is, translation to the next line and carriage shift to the left, to the beginning of the line. Or maybe just # 10. Different operating systems have different line completion options. In the fscanf example, for reasons not yet understood, I missed the symbol r (code # 13) and went straight to n (code # 10). That is, we waited for reading the appearance of n and came out =)
It depends on how the file is read. If character by character, then compare the read character with the newline character '\ n'. If byte-bye, then compare with acc. sequences of bytes (different on different OS). And you can simply take the lines directly with getline.
- Here it turns out that when using the >> operator, any \ n is automatically skipped. - jurbasiq
- If, for example, numbers from an unformatted file are entered, then nothing. - DUP
n - newline character
- i.e. canon line takes 3 lines? :) - zavtramen
- not. meant the symbol '\\ n' - sudo97
While reading, to test each character character by '\n'
, if the character is equal to '\n'
, then add one more line.