C语言完美演绎7-14
/* 范例7-14 */#include stdio.h#include string.hint main(void){/* 设定stpcpy、strcpy、strncpy函数的参数dest */char mystpcpy[10];char mystrcpy[10];char mystrncpy[10];char bigmystrncpy[10];/* 设定stpcpy、strcpy、strncpy函数的参数src */char *str1 abcdefghi;char *str2 tiger is good;/* 用四个指针变量(a、b、c、d)接收stpcpy、strcpy、strncpy函数的返回值 */char *a,*b,*c,*d;a stpcpy(mystpcpy, str1);b strcpy(mystrcpy, str1);c strncpy(mystrncpy, str1,3); /* 稍后再将\0加到所复制的字符串结尾 */d strncpy(bigmystrncpy, str2,13);mystrncpy[3]\0; /* 加上\0以保持字符串的完整性 *//* 输出mystpcpy[10]、mystrcpy[10]、mystrncpy[10] */printf(这是用stpcpy复制%s\n, mystpcpy);printf(这是用strcpy复制%s\n, mystrcpy);printf(这是用strncpy复制%s\n, mystrncpy);aa-5; /* 指针变量a指向mystpcpy的结尾(\0)将其往前推5个字符 *//* 输出四个指针变量(a、b、c、d) */printf(\na%s,\ta%u\tmystpcpy%u,a,(void*) a,mystpcpy);printf(\nb%s,\tb%u\tmystrcpy%u,b,(void*) b,mystrcpy);printf(\nc%s,\t\tc%u\tmystrncpy%u,c,(void*) c,mystrncpy);printf(\nd%s,\td%u\tbigmystrncpy%u,d,(void*) d,bigmystrncpy);getchar();return 0;}程序执行结果这是用stpcpy复制abcdefghi这是用strcpy复制abcdefghi这是用strncpy复制dbcaefghi, a6618620 mystpcpy6618616babcdefghi, b6618604 mystrcpy6618604cdbc, c6618592 mystrncpy6618592dtiger is goodbc, d6618580 bigmystrncpy6618580