Naruszenie zasad dostępu podczas używania strcpy?
Próbowałem ponownie odkryć funkcję strcpy C, ale gdy próbuję ją uruchomić, pojawia się ten błąd:
Unhandled exception at 0x00411506 in brainf%ck.exe: 0xC0000005: Access violation writing location 0x00415760.
Błąd występuje w*dest = *src;
linia. Oto kod:
char* strcpy(char* dest, const char* src) {
char* dest2 = dest;
while (*src) {
*dest = *src;
src++;
dest++;
}
*dest = '\0';
return dest2;
}
EDIT: Wow, to było szybkie. Oto kod wywołujący (strcpy jest zdefiniowany w mystring.c):
#include "mystring.h"
#include <stdio.h>
int main() {
char* s = "hello";
char* t = "abc";
printf("%s", strcpy(s, t));
getchar();
return 0;
}