1.strcpy
#include <stdio.h>
int main(void)
{
char src[32] = {0};
char dst[32] = {0};
int i = 0;
gets(src);
while (src[i] != '\0')
{
dst[i] = src[i];
i++;
}
dst[i] = '\0';
printf("dst = %s\n", dst);
return 0;
}
2.strcat
#include <stdio.h>
#include <string.h>
int main(void)
{
char str1[32] = {0};
char str2[32] = {0};
int len1 = 0;
int len2 = 0;
int i = 0;
int j = 0;
gets(str1);
gets(str2);
i = strlen(str1);
while (str2[j] != '\0')
{
str1[i] = str2[j];
i++;
j++;
}
str1[i] = '\0';
#if 0
len1 = strlen(str1);
len2 = strlen(str2);
for (i = 0; i < len2; i++)
{
str1[len1+i] = str2[i];
}
str1[len1+i] = '\0';
#endif
printf("%s\n", str1);
return 0;
}
3.strcmp
#include <stdio.h>
int main(void)
{
char str1[32] = {0};
char str2[32] = {0};
int i = 0;
int ret = 0;
gets(str1);
gets(str2);
while (str1[i] == str2[i] && str1[i] != '\0')
{
i++;
}
printf("ret = %d\n", str1[i] - str2[i]);
return 0;
}
4.strlen
#include <stdio.h>
int main(void)
{
char str[32] = {0};
int i = 0;
gets(str);
while (str[i] != '\0')
{
i++;
}
printf("%d\n", i);
return 0;
}