c语言中将不同类型数据组成字符数组\\sprintf()函数

include<stdio.h>库中存在sprintf()函数能将不同类型的数据组合成字符数组

sprintf(destination,type,各种数据名)

  //destination为最终组合成的字符数组返回目标,type为组合的各类型数据的类型(与printf()中使用的相似)

instance (eg):

  #include<stdio.h>
  #include<string.h>
  int main() {
  	int haha = 1;
  	char x = 'j';
  	float a = 1.10;
  	char s[100];
  	sprintf(s, "%c%d %.1f\n%c", 'e', haha, a, x);
        printf("%s",s);
  	return 0;
  }

output:
e9 1.1 j

posted @ 2020-08-19 17:37  Auterman  阅读(318)  评论(0编辑  收藏  举报