Guest_imported
New member
- Jan 1, 1970
- 0
Hello
as you know strcpy can be fatal, if dest is not as big as src. In this case an error can occur.
For this I did my own strcpy-function:
//Allocates memory for dest as much as needed
void scopy(char *dest, const char *src)
{
if ( (dest = (char*) malloc( (strlen(src) + 1) * sizeof(char) ) ) != NULL )
strcpy(dest, src);
else
{
fprintf(stderr,"Error while copying string\n",);
exit(1);
}
}
But this permanently causes errors. What's wrong?
Any help is greatly appreciated.
Thanks in advance.
BinLadenKiller
as you know strcpy can be fatal, if dest is not as big as src. In this case an error can occur.
For this I did my own strcpy-function:
//Allocates memory for dest as much as needed
void scopy(char *dest, const char *src)
{
if ( (dest = (char*) malloc( (strlen(src) + 1) * sizeof(char) ) ) != NULL )
strcpy(dest, src);
else
{
fprintf(stderr,"Error while copying string\n",);
exit(1);
}
}
But this permanently causes errors. What's wrong?
Any help is greatly appreciated.
Thanks in advance.
BinLadenKiller