0
点赞
收藏
分享

微信扫一扫

常用字符串函数的应用

常用字符串函数包括:gets( )   puts( )   strlen( )   strcat( )    strcmp( )    strcpy( )

程序代码

#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>

#include <string.h>

int main()

{

      char c1[10], c2[20], c3[50];

      printf("请输入两个字符串c1,c2");

      gets(c1);

      gets(c2);

      strcat(c2, c1);

      printf("字符串 I love China!的长度是:%d\n", strlen("I love China!"));

      strcpy(c3, c1);

      printf("将 c1复制到c3,结果:");

      puts(c3);

      printf("比较两个字符串c2,c3的结果:

      if (strcmp(c2, c3) == 0)

         printf("c2=c3\n");

      else if (strcmp(c2, c3) > 0)

         printf("c2>c3\n");

      else

         printf("c2<c3\n");

         return 0;

}

程序运行结果

常用字符串函数的应用_#include

举报

相关推荐

0 条评论