scanf与sprintf

来源:互联网 发布:无人机软件开发 编辑:程序博客网 时间:2024/06/10 22:10

scanf: 从字符串中拆分出想要的类型

sprintf: 把各种类型的东西合成一个字符串


#include <stdio.h>int main(void){    char *buf = "1:23:abc";    int a, b;    char c[5];    char d[10];    sscanf(buf, "%d:%d:%s", &a, &b, c);    printf("a = %d\n", a);    printf("b = %d\n", b);    printf("c = %s\n", c);    snprintf(d, 10, "%d,%d,%s", a, b, c);    printf("d = %s\n", d);    return 0;}


0 0
原创粉丝点击