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
  • 相关阅读:
    siteserver学习笔记
    移动端开发适配的2中方案
    移动端中适配问题
    2倍图3倍图怎么用
    常用的网站收藏
    关于用h5实现移动端的知识梳理
    悬浮广告代码
    vue中添加echarts
    VUE中给template组件加背景
    纯CSS控制背景图片100%自适应填充布局
  • 原文地址:https://www.cnblogs.com/xiaochi/p/8135167.html
Copyright © 2011-2022 走看看