A
ashok.anbalan
I have a simple strcpy implementation below. I have not malloc'd any
memory for "dest" in the function my_strcpy. I also keep doing dest++
in the loop. I would like to know why does the program *not* core dump?
/-----------------------------------------------------------------/
#include <stdio.h>
void my_strcpy(char *dest, const char *src)
{
while (*src != '\0')
{
*dest = *src;
dest++;
src++;
}
*dest = '\0';
}
int main()
{
const char *src = "hello world";
char *dest;
my_strcpy(dest, src);
printf("dest is %s\n", dest);
return 0;
}
/-----------------------------------------------------------------/
Thanks,
Ashok
memory for "dest" in the function my_strcpy. I also keep doing dest++
in the loop. I would like to know why does the program *not* core dump?
/-----------------------------------------------------------------/
#include <stdio.h>
void my_strcpy(char *dest, const char *src)
{
while (*src != '\0')
{
*dest = *src;
dest++;
src++;
}
*dest = '\0';
}
int main()
{
const char *src = "hello world";
char *dest;
my_strcpy(dest, src);
printf("dest is %s\n", dest);
return 0;
}
/-----------------------------------------------------------------/
Thanks,
Ashok