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 support@ccsinfo.com

strcpy question

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



Joined: 23 Apr 2004
Posts: 14
Location: Pescara (Italy)

View user's profile Send private message

strcpy question
PostPosted: Tue Jun 29, 2004 4:01 am     Reply with quote

Is strcpy function in string.h correct ?
It seems that it doesn't copy the '\0' too in destination string:
s2 is {'h','e','l','l','o','\0'} and s1 is {'1','1','1','1','1','1'}
after strcpy(s1,s2), s1 is {'h','e','l','l','o','1'} and not {'h','e','l','l','o','\0'}.

Is it right ?
Paolino



Joined: 19 Jan 2004
Posts: 42

View user's profile Send private message

PostPosted: Tue Jun 29, 2004 4:56 am     Reply with quote

I think there are some mis-understandings. I think s1 and s2 should have the same length. With the strings given strlen() function should return 5 for s2 and 6 for s1. Try with the example given in CCS help (look for STRLEN). It is not possible to do a=strlen("hello"); you must use arrays.

Best wishes.

Paolo.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Tue Jun 29, 2004 6:12 am     Reply with quote

It looks like a bug to me.

In v3.187 this is the code from string.h for strcpy():
Code:
/*    Standard template: char *strcpy(char *s1, const char *s2)
copies the string s2 including the null character to s1*/

char *strcpy(char *s1, char *s2)
{
  char *s;

  for (s = s1; *s2 != 0; s++, s2++)
     *s = *s2;
  return(s1);
}


According to the comment (and the ANSII standard) the nul character is too be copied, but it isn't.....
Please report this bug to support@ccsinfo.com
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