gpt4 book ai didi

c - 如何生成文件名序列

转载 作者:行者123 更新时间:2023-11-30 17:42:08 28 4
gpt4 key购买 nike

我希望向参数添加多个部分。

像这样,我知道在 VB.net 中我可以做到

messagebox("hello" + textbox1.text) // yields hello and whatever is in textbox1

但我该如何用 C 语言做到这一点?

我尝试了 &+ 但它给了我错误。

我想创建5个文件,并使用for循环来创建它们,数1-5

ofp = fopen("data" + (loop counter) + ".txt", "r"); // allong those lines...

因此文件名将是 data1.txt;data2.txt;data3.txt 等等。

谢谢

最佳答案

在这种情况下,您可以使用 snprintf:

char buffer[FILENAME_MAX];
snprintf(buffer,FILENAME_MAX,"data%d.txt",counter+1); //You will probably start counter at 0

buffer[FILENAME_MAX-1]=0;// snprintf may skip null terminator.
FILE* ofp=fopen(buffer,"w");
//...
fclose(ofp);

关于c - 如何生成文件名序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20789705/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com