zoukankan      html  css  js  c++  java
  • 11.字符,字符常见开发,_itoa函数

    • 各种字符所占字节
    1. wchar_t wch = L'我'; //占4个字节
    2. char ch;//占1个字节
    3. printf("%d ", sizeof("A"));  //占两个字节,因为字符串末尾有'/0'
    4. printf("%d ", sizeof("我"));  //占三个字节,中文占两个字节
    • sprintf函数 
       1 #define _CRT_SECURE_NO_WARNINGS
       2 
       3 #include <stdio.h>
       4 #include <stdlib.h>
       5 #include <time.h>
       6 #include <Windows.h>
       7 
       8 
       9 void main()
      10 {
      11     srand(time(0));
      12     char str[100] = { 0 };
      13     int num;
      14     while (1)
      15     {
      16         num = rand() % 10;
      17         sprintf(str, "color %d%c", num, 'e');
      18         Sleep(1000);
      19         system(str);
      20     }
      21 
      22 
      23     system("pause");
      24 }
      View Code

       //_itoa(100, res, 2); //第一个参数是十进制的数,第二个参数是char型数组,存放结果,最后一个是要转成的进制

      sprintf函数也可以实现字符串加法的功能   

        
     1  #define _CRT_SECURE_NO_WARNINGS
     2 #include <stdlib.h>
     3 #include <stdio.h>
     4 
     5 void main()
     6 {
     7     char str[10] = "task";
     8     char newstr[10] = "list123";
     9     char strall[100] = { 0 };
    10 
    11     sprintf(strall, "%s%.4s", str, newstr);//字符串加法
    12 
    13     system(strall);
    14     system("pause");
    15 }
    View Code
  • 相关阅读:
    Hadoop学习路线图
    windows命令——taskmgr 1
    windows命令——explorer
    windows命令——taskkill
    struts tags
    jsp的 javascript中 嵌套 html 注释
    netstat
    没有、不愿、不能足够交流、沟通的开发、测试,将是悲剧
    linux java so 历险
    linux java 版本
  • 原文地址:https://www.cnblogs.com/xiaochi/p/8135167.html
Copyright © 2011-2022 走看看