#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 100
//c语言模拟strcpy函数,将str2复制到str1中,无返回值
void my_strcpy(char * str1, const char * str2);
int main()
{
char str1[N], str2[N];
printf("输入字符串:\n");
while(scanf("%s", str2) != EOF)
{
my_strcpy(str1, str2);
printf("%s %s\n长度对比:%d %d\nstrcmp对比(相等返回0):%d\n", str1, str2, strlen(str1), strlen(str2), strcmp(str1, str2));
printf("继续输入或者输入control+z结束(EOF):\n");
}
return 0;
}
void my_strcpy(char* str1, const char* str2)
{
int i = 0;
while((str1[i] = str2[i++]) != '\0') ;
}
#include <stdlib.h>
#include <string.h>
#define N 100
//c语言模拟strcpy函数,将str2复制到str1中,无返回值
void my_strcpy(char * str1, const char * str2);
int main()
{
char str1[N], str2[N];
printf("输入字符串:\n");
while(scanf("%s", str2) != EOF)
{
my_strcpy(str1, str2);
printf("%s %s\n长度对比:%d %d\nstrcmp对比(相等返回0):%d\n", str1, str2, strlen(str1), strlen(str2), strcmp(str1, str2));
printf("继续输入或者输入control+z结束(EOF):\n");
}
return 0;
}
void my_strcpy(char* str1, const char* str2)
{
int i = 0;
while((str1[i] = str2[i++]) != '\0') ;
}