0

I have 80+ text files which I am current'y reading into the program using 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].

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.

0

1 Answer 1

1

You can create multiple filename0.txt, filename1.txt, etc using:

for (i=0; i<n; i++) {
    char buf[32];
    sprintf(buf, "filename%d_%s_%d", i, ArrayName[i], ArrayPercentage[i]);
}
Sign up to request clarification or add additional context in comments.

1 Comment

use snprintf instead to avoid buffer overrun

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.