开发者

create numbered files in C

开发者 https://www.devze.com 2022-12-20 08:46 出处:网络
I need to create files that have the same name, but with a number attached to the end of the filename to indicate that it was the nth file made. So in a for loop, I basically want to do this:

I need to create files that have the same name, but with a number attached to the end of the filename to indicate that it was the nth file made. So in a for loop, I basically want to do this:

char *filename = "file";
str开发者_如何学JAVAcat(filename, i); // put the number i at the end of the filename

Clearly that isn't the way to do it, but any ideas as to how I can accomplish this task?

Thanks,

Hristo


sprintf() or snprintf() with "file%d".


How about something like this?

char filename[256];
int i = 1;

// codes omitted...
sprintf(filename, "file%4d", i);


You can use sprintf.

0

精彩评论

暂无评论...
验证码 换一张
取 消