一、strcpy()函数:实现字符串的复制
实现将数组s1中的字符串复制到数组s2中
#include<stdio.h>
#include<string.h>
#define N 66
void strcopy(char s2[],char s1[]){
//方法一:
/*
int i = 0;
int j = 0;
while(s1[i]){
s2[j++] = s1[i++];
}
s2[j] = '\0';
*/
//方法二:
/*
int i = 0;
int j = 0;
while(1){
s2[j++] = s1[i++];
if('\0' == s2[j-1]){
break;
}
}
*/
//方法三:
/*
int i = 0;
int j = 0;
while(s2[j] = s1[i]){
i++;
j++;
}
*/
//方法四:
int i =0;
int j =0;
while(s2[j++] = s1[i++]);
}
int main(){
char s1[N];
char s2[N];
printf("请输入字符串:");
gets(s1);
strcopy(s2,s1);
puts(s2);
return 0;
}
二、strcat()函数:实现字符串的拼接
实现将数组s2拼接在数组s1后面
#include<stdio.h>
#include<string.h>
#define N 66
void strCat(char s1[],char s2[]){
//方法一:
/*
int i =0,j = strlen(s1);
while(s2[i]){
s1[j++] = s2[i++];
}
s1[j] = '\0';
*/
//方法二:
/*
int i = 0, j = strlen(s1);
while(1){
s1[j++] = s2[i++];
if(s1[j-1] == '\0'){
break