I am trying to learn c.( I want to play with kernels and embedded systems)
You are brave... C is not that hard to learn, because its library and its possible expressions are only a subset of C++ (yes the C++ standard library contains the whole C standard library...). The downside is that you are now at a much lower level and will have to code by hand all the goodies (dynamic vectors, maps, etc.) or find third party libraries.
The rationale is that is allows/forces the programmer to use custom algorithms to solve common problems, which can lead to nice optimizations in a given context. Here, for example, if you are short in memory but execution time is not that sensitive, you should read one character at a time, and realloc often your buffer by short increments. If memory is not that sensitive, you would use larger buffers and read larger data chunks. If you do not know, do not try to invent an oval wheel when round ones are already available, and search the GNU libraries to see if you problem is not already solved.
Do not expect to be a genius: writing C code is (rather) easy, but writing robust yet efficient code is hard and requires extensive tests. So the rule is:
- if it already exists and covers your requirements: do use it
- only if the above conditions are not met: code it from scratch
malloc. Then in a loop read one character at a time, reallocating (withrealloc) the array over and over again. Once done, do one last reallocation to add the terminating null character.getlinefor C.getlinefunction. It's very likely that someone has ported it to Windows, if that's your target.%swill get you a word so it's not like C++'sstd::getline