It sure is too bad no one else suggested any alternative to what you were doing in this thread.
Quzah.
It sure is too bad no one else suggested any alternative to what you were doing in this thread.
Quzah.
Hope is the first step on the road to disappointment.
That sound you just heard was my post going right over your head.
Quzah.
Hope is the first step on the road to disappointment.
Ok,i put the terminating '\0' .However program is not correct again.I noticed that every time i read a line in the loop of while,if the position was before held by a letter and now it has to be overwritted by tab,causes the problem.
e.g (the names are seperated by tab,but bellow i have put space)
Then these are going to be saved asCode:Wood Gina Ray Vickie Cobb Dale
When i write Rayd instead of Ray everything is ok.When i write Ra instead of Ray i getCode:Wood Gina Rayψ Vickie Cobb Dale
Code:Wood Gina RaQψ Vickie Cobb Dale
That means you didn't do the terminating \0 very well.
I don't know why you are subtracting one. Returning s could be dangerous depending on whether you actually use the return value, since at the end of the function s points to the null character.
You don't really have to do that -- passing a char* is fine, since the individual char's themselves are editable, which is the point. But if you had been doing something like
then the return would trash name.Code:name = put_NULL_at_end(name, 4);
Does this seems ok?Code:void put_NULL_at_end(char **s , unsigned int size_for_malloc) { *s+=size_for_malloc; **s='\0'; }
Last edited by std10093; 05-19-2011 at 05:31 PM.
That should work, since I think we have size_for_malloc calculated correctly up above, and hopefully you are using it after every strncpy.