hallo,
i am in search of solution for the following problem . i have nearly 100 files and i need to read them. how is it possible.
bye
sudhir
hallo,
i am in search of solution for the following problem . i have nearly 100 files and i need to read them. how is it possible.
bye
sudhir
Something like this?
(assumes that your files are named sensibly eg myfile1.dat, myfile2.dat, myfile3.dat ... etc.)Code:#include <stdio.h> int main(void) { for (i = 1; i <= 100; i++) { FILE * pFile; char filename[20]; sprintf(filename, "myfile%d.dat", i); if ((pFile = fopen(filename, "r")) == NULL) { printf("could not open file %s\n", filename); exit(1); } /* .... do whatever you want to do with the file .... */ fclose(pFile); } return 0; }
DavT
-----------------------------------------------
Or if you don't have any system in the filenames, use a lookup list:
Code:#define NrOfFiles 6 const char* FileName[] = { "MyFile1.txt", "MyFile2.txt", "OurFile.txt", "Banana.txt", "YourFile.txt", "EveryonesFile.txt"}; ... FILE* ReadFile; for(int i = 0; i < NrOfFiles; i++) { ReadFile = fopen(FileName[i], "rb"); ... }
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
thank u guys the code is working
bye
sudhir