设为首页 加入收藏

TOP

C中字符串常见操作
2015-01-22 21:34:07 来源: 作者: 【 】 浏览:86
Tags:字符串 常见 操作
#include  
  
   
#include 
   
     #include 
    
      #include 
     
       #include 
      
        // #include 
       
         int main(void){ char str1[]="This is the first string"; char str2[]="That is the other string"; // printf(strcpy(str1,str2));//复制字符串 // printf(strncpy(str1,str2,20));//复制字符串指定长度内容 // printf("%d",strlen(str1));//字符串长度 // printf(strcat(str1,str2));//链接字符串 // printf(strncat(str1,str2,20));//链接指定长度字符串 // // printf("%d",strcmp(str1,str2));//比较字符串大小 // // printf("%d",strncmp(str1,str2,5));//比较指定长度的字符串大小 // char * pGot_char=strchr(str1,'i');//搜索字符,返回找到字符的地址 // printf("%c",*pGot_char);//打印地址的内容 // if(strstr(str1,"the")==NULL){//搜索子串 // printf("no found"); // } // else { // printf("has found"); // } // char buf[40]; // gets(buf);//将输入的字符串读入数组中,中间可以包含空格,直到回车,不同于scanf // printf("%s",buf); //相比gets,fgets可以指定输入字符串最大长度 //另外,gets只能用于标准输入流stdin,而fgets可以用于任意类型种类输入的字符串 //在输入换行符时,fgets会存储一个'\n'字符,而gets不会。 // fgets(buf,sizeof(buf),stdin); // printf("%s",buf); //atof字符串转double,atoi字符串转int //atol字符串转long,atoll字符串转longlong // char value_str []="99.4"; // double value =atof(value_str); // printf("%f",value); //宽字符串 // wchar_t proverb1[]=L"This is a wide type string"; // wchar_t proverb2[]=L"This is an other wide string"; // wchar_t wchar=L'w'; // wchar_t wsring[]=L"wide"; // printf("%S\n",proverb1);//打印必须使用%S,而不是%s. // // printf("%d\n",wcslen(proverb1));//宽字符串长度,不包含终止字符'\0' // // wcscpy(proverb1,proverb2);//复制宽字符串 // wcsncpy(proverb1,proverb2,15);//复制指定长度 // wcscat(proverb1,proverb2);//连接宽字符串 // wcscmp(proverb1,proverb2);//比较大小 // wcsncmp(proverb1,proverb2,15);//比较指定长度的宽字符串大小 // wcschr(proverb1,wchar);//搜索宽字符 // wcsstr(proverb1,wsring);//搜索宽字符串 wchar_t ina[80]=L"ss"; fgetws(ina,sizeof(ina),stdin);//获取输入的宽字符串,指定了最大长度,和标准输入流 printf("%S",ina); return 0; }
       
      
     
    
   
  

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C语言 对数组名取地址 下一篇C 语言实现多态的原理:函数指针

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: