本文共 700 字,大约阅读时间需要 2 分钟。
相关博文:
相关博文: 相关博文: 相关博文: 相关博文: 相关博文: 相关博文: 相关博文: 相关博文: 相关博文: 相关博文: 相关博文:int sprintf(char ∗ \ast ∗ str,const char ∗ \ast ∗ format,…)
功能: 根据参数format字符串来转换并格式化数据,然后将结果输出到str指定的空间中,直到出现字符串结束符’\0’为止。 功能: str:字符串首地址 format:字符串格式,用法和printf()一样 返回值: 成功:实际格式化的字符个数 失败:-1例1:
//小问学编程#include#include int main(){ int a,b,c,d; printf("pls input ip:"); scanf("%d.%d.%d.%d",&a,&b,&c,&d); char buf[16]; sprintf(buf,"%d.%d.%d.%d",a,b,c,d); printf("%s\n",buf); return 0;}
例2:
//小问学编程#include#include int main(){ char buf[1024]={ 0}; sprintf(buf,"Hello %s!","Obama"); printf("buf:%s\n",buf); return 0;}
转载地址:http://ashp.baihongyu.com/