Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   Help about making directory and write files into that (http://www.go4expert.com/forums/help-directory-write-files-t1900/)

sitha 15Nov2006 15:24

Help about making directory and write files into that
 
Hi Everybody,
I am little new to C++ program. I want to write a program which could be able to read data from files which is in a folder.
Following my program could be able to read all data in files.
Now say each files has 10 lines of data.
My program should read each files first line data and put it into a folder in a file, name result1, then it should read second data of each files and put it into the folder with file name result2. and so on................

This is my code,
Code:

int printFiles(char * dirname)
{
  char* POV;
  DIR* dirp;
  string buff;
  struct dirent* dp;
 
  system("mkdir POV");
  ofstream output("test.pov");
 
 
 
  dirp = opendir(dirname);
  if ( !dirp )
  {
      cout << "Error: failure opening directory" << endl;
      exit(1);
  }
 
  errno = 0;

 
  while ( dp = readdir(dirp) )  {
          if(dp !=NULL) {
                 
      if(strstr(dp->d_name, ".dat"))  {
             
                       
        ifstream input(dp->d_name);       
        while( getline(input, buff) )
        {
             
            cout << buff << endl;
            output<< buff << endl;
          }
       
      }
  }
     
      if ( errno )
      {
        cout << "Error: readdir() failure!" << endl;
        exit(1);
      }   
  }

  closedir( dirp );
 
 
}

Here I dont know how to read each files data and put them into corresponding files.

Pls help me.

Regards,
Sitha.


All times are GMT +5.5. The time now is 15:59.