CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

strncpy

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
young



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

strncpy
PostPosted: Tue Feb 08, 2005 4:10 pm     Reply with quote

I am copy one string to another but when I print out, it is wired data after the copyed data why? here is the program and the outptut


char termp[20],data[20];
int8 length;
length=strlen(termp);
gets(termp); //termp=" 112.7880T1"
strncpy(data,termp,length-2);
puts(data);

output

\0A 111.71207T1ªòÿÿCÿŸ·îþÿ¯ýïý÷¿Ý¶ïwÿ \0D

I do not know why "ªòÿÿCÿŸ·îþÿ¯ýïý÷¿Ý¶ïwÿ " is coming out?
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Tue Feb 08, 2005 5:35 pm     Reply with quote

strncpy doesn't seem to be terminating the copy at the \0. Look at your LST file. If there is a bug, then write your own version of strncpy.
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group