#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int str_copy(char* from, char* to) {
char* myfrom = from;
char* myto = to;
if (from == NULL || to == NULL) {
return -1;
}
while (*myto++ = *myfrom++);
printf("%s\n", to);
printf("%s\n", from);
}
int main() {
char* from = "abvcd";
char buf[128] = { 0 };
str_copy(from, buf);
system("pause");
return 0;
}
这是一个C语言程序,定义了一个名为str_copy的函数,用于复制字符串。如果输入指针为NULL,函数返回-1;否则,它会逐个字符地从源字符串复制到目标字符串,并在复制完成后打印出两个字符串。在主函数中,调用str_copy函数将字符串abvcd复制到buf数组中。程序最后使用system(pause)暂停,以便查看输出结果。
1341

被折叠的 条评论
为什么被折叠?



