Violação de acesso ao usar o strcpy?
Eu tentei reinventar a função strcpy C, mas quando tento executá-lo eu recebo este erro:
Unhandled exception at 0x00411506 in brainf%ck.exe: 0xC0000005: Access violation writing location 0x00415760.
O erro ocorre no*dest = *src;
linha. Aqui está o código:
char* strcpy(char* dest, const char* src) {
char* dest2 = dest;
while (*src) {
*dest = *src;
src++;
dest++;
}
*dest = '\0';
return dest2;
}
EDIT: Uau, isso foi rápido. Aqui está o código de chamada (o strcpy está definido em mystring.c):
#include "mystring.h"
#include <stdio.h>
int main() {
char* s = "hello";
char* t = "abc";
printf("%s", strcpy(s, t));
getchar();
return 0;
}