c语言中的sprintf函数的使用

sprintf函数的功能与printf函数的功能基本一样,只是它把结果输出到指定的字符串中了:

#include<stdio.h>
int main(int argc, char *avgv[])
{
    char s[40];
    sprintf(s,"%s%d%c","test",1,'2');
    /*第一个参数就是指向要写入的那个字符串的指针,剩下的就和printf()一样了*/
 
//  printf("%s%d%c","test",1,'2'); //test12
    printf("%s",s);   //test12
    return 0;
}

猜你喜欢

转载自blog.csdn.net/dyd850804/article/details/80627182