Subj : Re: malloc() To : borland.public.cpp.borlandcpp From : Jan Vernimmen Date : Sat Jun 26 2004 06:48 pm Hello everybody, I have found the error, because due to the reactions I went through the program and through and.. again! Jan Vernimmen wrote: > //-------------------------- > > if ( strlen( szInput ) > strlen( txtBuf )) > { > free(txtBuf); > txtBuf = (char *)malloc( strlen( szInput ) + 1 ); > } > strcpy( txtBuf, szInput ); > > //-------------------------- > > I have programmed the following working solution: > txtBuf = (char *)malloc( strlen( szInput ) + 2 ); // mind + 2!! > AFTER this point I copied one input-char into txtBuf and not before as my code is more or less suggesting; so malloc( strlen( szInput ) + 2 ) is correct and explainable at this point. The reactions were very instructive for me and will give me reasons to change my program at a view places. With thanks for all the comments, Jan Vernimmen. .