[英]File Names Stored in an array and need to iterate through array creating a new file based on the name stored in each cell in C
I have 80+ text files which I am current'y reading into the program using dirent.h
. 我有80多个文本文件,目前正在使用
dirent.h
读入程序。 This is placing them in an array, I am throwing them each through an algorithm which will compare the contents of each file to the other contents within that file and provide me with a percentage of how identical things within the file are. 这是将它们放置在一个数组中,我通过一种算法将它们扔给每个算法,该算法会将每个文件的内容与该文件中的其他内容进行比较,并为我提供文件中相同内容的百分比。 While doing that it will store the name of the file in
ArrayName[i]
and the percentage in ArrayPercent[i]
. 这样做时,它将文件名存储在
ArrayName[i]
,并将百分比存储在ArrayPercent[i]
。
I am pretty sure I know how to print those array values to a file, that is not the problem, the problem is using a variable as the filename. 我很确定我知道如何将这些数组值打印到文件中,这不是问题,问题在于使用变量作为文件名。 My current thoughts are something along the lines of
我目前的想法是
fprintf(**DIRECTORY HERE**,"%s %d", ArrayPercent[i], ArrayName[i][]);
The first time through a loop ArrayName[0]
needs to go in DIRECTORY HERE as the filename.txt and the second time through ArrayName[1]
needs to go there as filename1.txt for argument sake and so forth for the remainder of ArrayName
. 第一次通过循环
ArrayName[0]
需要进入DIRECTORY HERE作为filename.txt,第二次通过ArrayName[1]
需要在那里以filename1.txt作为参数,对于其余的ArrayName
。
You can create multiple filename0.txt, filename1.txt, etc using: 您可以使用以下命令创建多个filename0.txt,filename1.txt等:
for (i=0; i<n; i++) {
char buf[32];
sprintf(buf, "filename%d_%s_%d", i, ArrayName[i], ArrayPercentage[i]);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.