zalzon said:
Do I have to use char * string and then malloc memory to it?
But malloc(size) can only gurantee that size is allocated. What if the
string is more than size?
Is there any way to find the size of the string before taking it in and
THEN malloc the needed amount?
I'm in a rut, help me please
From what you've posted, it looks like you really want string *input*
of an arbitrary size. I have written up a fairly comprehensive
article on the issue, with included source, here:
http://www.azillionmonkeys.com/qed/userInput.html
However, C's whole \0 terminated, and fixed buffer paradigm is
annoying for more issues than just input. I've written a safe,
portable and fast library that lets you substantially ignore C's
limited char buffer nonsense, and treat strings closer to how most
other programming languages do it here:
http://bstring.sf.net/
This library also includes very simplistic input functions for
arbitrary input streams (not necessarily just files). Most
importantly it is interoperable with C's char * paradigm (so if you
are forced to use C semantics, you aren't screwed) and comes with a
complement of functions that totally supersets the C's string handling
functions.