| Tekststrenge - slide 25 : 38 |
char *strcpy(char *s1, const char *s2)
Funktionen strcpy kopierer en tekststreng s2 ind i et char array s1, til og med det afsluttende 0-tegn
strcpy antager at der er plads nok i arrayet - hvis ikke overskrives nabo celler i lageret
#include <stdio.h>
#include <string.h>
int main(void) {
char source[] = "Aalborg";
char target_1[8], target_2[5];
strcpy(target_1, source); // Enough space in target_1.
printf("%s: %i chars\n", target_1, strlen(target_1));
strcpy(target_2, source); // Insufficient space in target_2. Very problematic.
printf("%s: %i chars\n", target_2, strlen(target_2));
return 0;
}





