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;

    }

  • 相关阅读:
    es 报错cannot allocate because allocation is not permitted to any of the nodes
    linux下获取软件源码包 centos/redhat, debian/ubuntu
    windows假死原因调查
    k8s-calico
    helm使用
    docker网络模式
    4、formula 法则、原则、数学公式
    powershell自动添加静态IP
    WDS部署Windows server2012初试
    2、puppet资源详解
  • 原文地址:https://www.cnblogs.com/wanghong19991213/p/13616019.html
Copyright © 2011-2022 走看看