作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我希望向参数添加多个部分。
像这样,我知道在 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/
我是一名优秀的程序员,十分优秀!