sprintf与sscanf

sscanf与sprintf

str与int的互转

  • sscanf():str->int

    • 用法:sscanf(str,"%d",&n);

      • 1
        2
        3
        4
        5
        6
        7
        8
        #include <stdio.h>
        int main()
        {
        int n;
        char str[100]="1223343";
        sscanf(str,"%d",&n);//从左向右传值
        printf("%d",n);
        }
      • 1
        1223343
  • sprintf():int->str

    • 用法:sprintf(str,"%d",&n);

      • 1
        2
        3
        4
        5
        6
        7
        8
        #include <stdio.h>
        int main()
        {
        int n=2333;
        char str[100];
        sprintf(str,"%d",n);//从右向左传值
        printf("%s",str);
        }
      • 1
        2333
凡希 wechat
喜欢所以热爱,坚持干货分享,欢迎订阅我的微信公众号
呐,请我吃辣条