|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to read multiple files?
I want to read about 154 files with names as in1 to in154.
I want to open each file, read the data, sort & then store in respective 154 files, like out1-out154. I'm using following code char fileName[] = "in1.txt"; ifstream inFile; inFile.open(fileName); how can i read filenames with some loop? please help as soon as possible. Thanx. |
|
#2
|
||||
|
||||
|
Something like this maybe?
Code:
#include <cstdio>
char fileName[100];
for (int i=1; i <= 154; i++) {
sprintf(fileName, "in%d.txt", i);
ifstream inFile;
inFile.open(fileName);
}
|
|
#3
|
||||
|
||||
|
Here's a related question:
Is there a defined limit on the number of file handles for windows systems, like there was in DOS? You should be careful with how many files you open at the same time, especially on a system that has limited file handles that runs more than one application at the same time.
__________________
Jason Doucette / Xona.com™ - Programming Windows Errata Addendum "Discussion is an exchange of knowledge; argument is an exchange of ignorance." |
|
#4
|
|||
|
|||
|
Thanks
Thanks for your help.
Ketaki. |
|
#5
|
|||
|
|||
|
code help
previous codes won`t work
in order to change the filenames you should create cycle to generate the number from 1 to 154, the next step is ot convert this integer numbers to strings and to insert these strings as substrings in the filename variable after position 1; ex. char dynvar[20]; char filename[20]; FILE *fp; strcpy(filename,"in.txt"); for (i=0;i<155;++i) { dynvar = itos(i); /* i`m not quite sure for the correct function check yourMSDN libraries for the correct one */ // here you should create function for inserting the substring // these could be done with memove(); function if (fp = fopen(dynvar,"r+b") == NULL) { printf("\nError opening file %s",filename"); exit(1); } } |
|
#6
|
||||
|
||||
|
Re: code help
Quote:
With all due respect, you're definitely smoking some interesting ceremonial chemicals. |
|
#7
|
|||
|
|||
|
I'm done !!
Thanks for your time.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > How to read multiple files? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|