|
|
View previous topic :: View next topic |
Author |
Message |
Lorenzo
Joined: 23 Apr 2004 Posts: 14 Location: Pescara (Italy)
|
strcpy question |
Posted: Tue Jun 29, 2004 4:01 am |
|
|
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
|
|
Posted: Tue Jun 29, 2004 4:56 am |
|
|
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
|
|
Posted: Tue Jun 29, 2004 6:12 am |
|
|
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 |
|
|
|
|
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
|