zoukankan      html  css  js  c++  java
  • 字符串

    #include <stdio.h>
    #include <string.h>
    int main()
    {
        char    str1[]="abcdefghijklmnopqretuvwxyz";
        char    str2[]="iiiii";
        
        char    str3[]="abcdefghijklmnopqretuvwxyz";
        char    str4[]="oooooooo";
        int count1,count2;
    
            count1=0;
        while (str1[count1])
            count1++;
            printf("
    %d
    ",count1);
    
        count2=strlen(str2);
            printf("%d
    ",count2);
    
        if(sizeof (str2)<=sizeof(str1))
        strcpy(str1,str2);
        printf("%s",str2);
            printf("
    
    %s",str1);
        
        count2=0;
        count1=8;
        while (str3[count2])    
        str4[count1++]=str3[count2++];
    
            printf("
    
    
    
    
    %s",str4);
        
        system("pause");
    
    
    }
    #include <stdio.h>
    int main()
    {
        char a[]="To be or not to be";
        char b[]=",that is a question";
        int count =0;
        while (a[count]!='')
            count++;
        printf("
     The length of the string "%s" is %d characters.
    ",a,count);
        count=0;
        while (b[count])
            count++;
        printf("
     The length of the string "%s" is %d characters.",b,count);
    
    system("pause");    
    return 0;
    
    }
    #include <stdio.h>
    int main()
    {
        char a[44]="To be or not to be";
        char b[]=",that is a question";
        int count1 =0;
        int count2 =0;
        while (a[count1]!='')
            count1++;
        printf("
     The length of the string "%s" is %d characters.
    ",a,count1);
    
        while (b[count2])
            count2++;
    
        printf("
     The length of the string "%s" is %d characters.",b,count2);
        
    
        if(sizeof a<count1+count2+1)
            printf("
     You can't do it ");
    
        else {
        
            count2=0;
            while (b[count2])
                a[count1++]=b[count2++];
            a[count1]='';
            printf("
    
    %s",a);   
        }
    
        system("pause");    
        return 0;
    
    }//连接字符串
    #include <stdio.h>
    int main()
    {    
        int i;
    
        char str[][40]={
        
            "To be or not to be",//18
            "that is a problem."//19
        };//二维数组声明
    
        int count[]={0,0};
    
        for(i=0;i<2;i++)
            while((str[i][count[i]])!=0)//!=0我加的
                count[i]++;
    
    
        /*   
        count[0]=0;
        i=0
        str[0][0]!=0
        count[0]++
        str[0][1]!=0
        count[0]++
        ...
        ...
        str[0][18]!=0
        count[0]==18
        str[0][19]=0
        跳出while 
    
    
        count[1]=0;
        i=1;
        str[1][count[1]]!=0
        count[1]++
        ...
        ...
    
        str[1][18]!=0
        count[1]++
        此时=19
        跳出while
        
        */
    
        if(sizeof str[0]<count[0]+count[1]+1)//count[0],count[1]分别为字符个数(不包括)
            printf("
     You can't put a quart into a pin pot.");
        else 
        {
            count[1]=0;//正好接到后面
            while (( str[0][count[0]++]=str[1][count[1]++] ));
            printf("
    %s
    ",str[0]);
        }
    
        system("pause");    
        return 0;
    
    }//字符串数组
    #include <stdio.h>
    #include <string.h>
    #define S 40
    int main(void)
    {
        char str1[S]="abcdefghijklmnopqretuvwxyz";
        char str2[S]="iiiiiiiiiiii";
        char str3[]="The quick brown fox";
        char str4[]="The quick black fox";
    
        if (S>strlen(str1)+strlen(str2))
            printf("
     %s 
    ",strcat(str1,str2));
        
        else 
            printf("
     You can't put a quart int a pint pot");
        
    
    
    
        if(strcmp(str3,str4)>0)
            printf("str3>str4");
        else 
            printf("str3<str4");
    
    
        system("pause");
        return 0;
        
    
        
    }
    #include <stdio.h>
    #include <string.h>
    #define S 40
    int main(void)
    {
    
        char str1[]="The quick brown fox";
        char str2[]="The quick black fox";
        char str3[]="The quick";
    
        if(strstr(str2,str3)==NULL)
            printf("shibai");
        else 
            printf("zhaodaole");
        system("pause");
        return 0;
        
    
        
    }
    #include <stdio.h>
    #include <string.h>
    #include <ctype.h>
    #define S 20
    int main(void)
    {
    
        char  buffer[S];
        int i=0;
        int num_letters =0;
        int num_digits =0;
    
        printf("
     Enter an interesting string of less than 80 ...");
    
        gets(buffer);
    
        if(gets(buffer)==NULL)
        {
        printf("Error input");
        return 1;
        }//检验gets函数是否出错(一般读取文件可能错),一般键盘输入不会出错(gets函数可以接受所有的字符包括空格 不像scanf那样遇见空格视为结束)
    
    
        while (buffer[i]!='')
        {
            if(isalpha(buffer[i]))
                num_letters++;
            if(isdigit(buffer[i++]))
                num_digits++;
        }
        printf("
    zhimu:%d
    shuzhi:%d
    ",num_letters,num_digits);
        
        system("pause");
        return 0;
        
    
        
    }
  • 相关阅读:
    vue使用watch 观察路由变化,重新获取内容
    Intellij IDEA 最新旗舰版注册激活破解(2018亲测,可用)
    前端开发浏览器兼容问题
    基于Docker搭建MySQL主从复制
    js获取计算后的样式表
    js对象取值的两种方式
    js中的style与jQuery中的css
    js页面加载函数
    代码中jndi数据源的支持
    Oracle中的sid与servicename
  • 原文地址:https://www.cnblogs.com/xinqidian/p/5581278.html
Copyright © 2011-2022 走看看