zoukankan      html  css  js  c++  java
  • 字符串格式化

    #define _CRT_SECURE_NO_WARNINGS
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #include<math.h>
    #include<time.h>

    //使用系统函数sprintf格式化写入;把格式化的数据写入某个字符串缓冲区

    int main0101()

    {

      char ch[100];

      sprintf(ch,"hello world");

      //sprintf(ch,"%d+%d=%d",1,2,3);

      printf("%s ",ch);

      return EXIT_SUCCESS;

    }

    //使用系统函数sscanf格式化读取元素

    int main0102(void)

    {

      char ch[]="1+2=3";

      int a,b,c;

      sscanf(ch,"%d+%d=%d",&a,&b,&c);

      printf("%d ",a);

      printf("%d ",b);

      printf("%d ",c);

      return 0;

    }

    //使用系统函数sscanf格式化读取字符串

    /*sscanf:从一个字符串中读进与指定格式相符的数据;scanf:格式输入函数,按用户指定的格式从键盘上把数据输入到指定的变量之中。前者以固定字符串为输入源;后者以键盘为输入源;两者都不接收空格或换行*/

    int main(void)

    {

      char ch[]="hello world";

      int a,b,c;

      char str1[100];

      char str2[100];

      //sscanf(ch,"%s",str1);//hello

      //sscanf(ch,"%11s",str1);//hello

      //sscanf(ch,"%[^ ]",str1);//hello world

      printf("%s",str1);

      sscanf(ch,"%5s %s",str1,str2);

      printf("%s ",str1);//hello 

      printf("%s ",str2);//world

      return 0;

    }

  • 相关阅读:
    python requests 上传excel数据流
    No module named 'requests_toolbelt'
    code
    pytest 打印调试信息
    python3 获取日期时间
    Java单元测试之JUnit篇
    The import junit cannot be resolved解决问题
    什么是索引
    python3 ini文件读写
    js 测试题
  • 原文地址:https://www.cnblogs.com/wanghong19991213/p/13616019.html
Copyright © 2011-2022 走看看