简介:sprintf函数调用的主要用途就是把一个字符串放在一个已知的字符数组里去
int main()
{
int score;
for(score=0;score<10;score++){
char str[];
sprintf(str,"%d",score);
printf("%s ",&str);
}
system("pause");
return 0;
}
//输出的结果是字符串:0 1 2 3 4 5 6 7 8 9
例如想统一生成文件名,从文件路径中生成文件名,加载文件
int main(){
char name[64];
IMAGE ImgPhotos[10];//加载图片的数组
for(int i=0;i<10;i++){
sprintf(name,"res/bg/%d.png",i);//res/bg等是文件路径和文件名
loadimages(&ImgPhotos[i],name);
}
system("pause");
return 0;
}
//生成文件名即字符串,打印到char name中,再按文件名将文件加载到ImgPhotos中