I'm writing a program and I want to put a written file inside a for loop. For each run through the loop, I want to write to a different file. How do I do this? Here's the code:
I tried putting a '%d' inside the fopen command where I specify the name of the file, but that obviously didn't work. Ideally, I'd like it to write files with the names sequence0.in, sequence1.in, etc. up to whatever value I feed it for the variable 'files.' Is there any way to do what I'm trying to accomplish?Code:for(f=0;f<files;f++) { srand(f); output= fopen("sequence.in","w"); //now open/create file for writing for(t=0;t<number;t++) { //bases are generated with the given frequencies rand=rnum(); if(rand<freqa) { base='A'; } if(rand>=freqa && rand< (freqa + freqt)) { base='T'; } if(rand>=(freqa + freqt) && rand< (freqa + freqt + freqg)) { base='G'; } if(rand>= (1 - freqc) && rand<1.00) { base='C'; } fprintf(output, "%c",base); } fprintf(output, "%c",'Q'); //add 'Q' to end of file (quit command in program that will read the file) fclose(output); }



LinkBack URL
About LinkBacks



