我希望向参数添加多个部分。
像这样,我知道在 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/