file writing and reading

This is a discussion on file writing and reading within the C Programming forums, part of the General Programming Boards category; Hi guys I need help
I'm writing a simple program than asks user to entere string and then write this ...

Every time only first string is returned. I understand what is happening. I allocate 500
elements of char assuming I don't know how much is enetered. Character '\0' is also written
and when I use puts(string) //string=Read(); in main() only first string is displayed.
How can I solve this problem. In geereal case how to read files taht contains strings variable size. Do I have to track length when writing and then to pass it in Read or...?
And what if I write to a file other data types such as integer? or maybe it is better to use structures then? Questions, question oooooooooohhh
Help me please!

>In geereal case how to read files taht contains strings variable size.
Don't use fread and fwrite for variable length memory blocks unless you have some way to find out what the size of the next block is. Since you are working with strings, just open the file as text and use fgets/fputs or something equally suitable. That way you can have a good definition of what a line is and the variable length problem is only a problem with the size of the array that you put the string in.

>but if someone have a better solution welcome
Read can be made to be more efficient, but I'm sure you can figure that one out without too much trouble. Hint: Remove malloc and free for every line, but still allow for variable length strings.