/* File: copy4.c Use string library copy function This version is safer. */ #include #include #include #include #define MAXLENGTH 12 int main() { char another[MAXLENGTH] = "Hello World" ; char *ptr, str[MAXLENGTH] ; ptr = readline("Enter string: ") ; printf("Length of string = %d\n", strlen(ptr) ) ; strncpy(str, ptr, MAXLENGTH) ; str[MAXLENGTH-1] = '\0' ; // terminate string! printf("Copy of string here: %s\n", str) ; printf("Another string: %s\n", another) ; free(ptr) ; return 0 ; }