In C++ (compiler : clang++), when compiling the following code:
char* strcpy(char * dest, const char * src)
{
char* result = dest;
if(('\0' != dest) && ('\0' != src))
{
/* Start copy src to dest */
while ('\0' != *src)
{
*dest++ = *src++;
}
/* put '\0' termination */
*dest = '\0';
}
return result;
}
I get the following error code:
string/strcpy.cpp:12:11: error: comparison between pointer and integer
('int' and 'char *')
if(('\0' != dest) && ('\0' != src))
~~~~ ^ ~~~~
string/strcpy.cpp:12:29: error: comparison between pointer and integer ('int'
and 'const char *')
if(('\0' != dest) && ('\0' != src))
I'm aware that most of the errors related with this error are produced when the characters to compare are between quotation marks instead of apostrophes, but in this code this is not the case. Why is this error produced? Thanks in advance!
destis a pointer.*destis the value of the thing it points to. You compare correctly later with'\0' != *src. Seems like a simple typo to me.strcpybad name.