I am trying to read Data from a Text file & storing it inside a structure having one char pointer & an int variable. During fetching data from file I know that there wil
Either
\0
into your malloc'd block there so it behaves correctly as a nul-terminated string (and/or save the length too in case you need it)Or
\0
etc. as aboveYou said in a comment that the max. string length is bounded, so the first approach is probably fine. You haven't said how you figure out where the string ends, but I'm assuming there is some delimiter, or it's right-filled with spaces, or something.