c 字符串与字符串操作

发布时间:2022-07-05 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了c 字符串与字符串操作脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

  

1,字符串输入与输出

char string[10];
scanf("%s",string);
PRintf("%sn",string);

 

c 字符串与字符串操作

 

 2,字符串长度

c 字符串与字符串操作

 

 

#include <stdio.h>
#include <string.h>
int main(){
  
     char string[100];
     scanf("%s",string);
     if(strlen(string)<=10){
        printf("%sn",string);
     }else{
        printf("Too Longn");
     }

     return 0;

}

 

3,字符串拷贝

在处理字符串的标准库中,有一个函数strcpy(表示string copy)用于复制字符串。

请先加上string.h 引入处理字符串的标准库。

#include <stdio.h>
#include <string.h>
int main(){
    
    char string[100];
    char copy[100]="";

    scanf("%s",string);
    strcpy(copy,string);
    printf("%sn",copy);
    return 0;

}

c 字符串与字符串操作

 

 

4,字符串字典序

c 字符串与字符串操作

 

 

c 字符串与字符串操作

c 字符串与字符串操作

 

5,字符串比较

 

#include<stdio.h>
#include<string.h>
int main(){
  
    char string[100]="hello";
    char input[100]="";

    scanf("%s",input);

    printf("%dn",strcmp(input,string));
    
    return 0;
 
}

 

 

c 字符串与字符串操作

 

脚本宝典总结

以上是脚本宝典为你收集整理的c 字符串与字符串操作全部内容,希望文章能够帮你解决c 字符串与字符串操作所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。