środa, 10 sierpnia 2016

Creat new files in class and next copy to files

vim new_files.cpp



#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <fstream>
#define min 3
#define max 7
#define max_files 100
using namespace std;


void init_random()
{
srand(time(NULL));
}


class New_files_copy
{
private:
char array_files[max_files][max];
char upper_letters[26];
char lower_letters[26];
int how_many;
int files[max_files];

public:
New_files_copy(char *main_file, int how_many_new_files)
{
char c,d;
int i,j,size,temp,letters;
how_many=how_many_new_files;


         

for(i=0,c='A',d='a';i<26;i++,c++,d++)
{
upper_letters[i]=c;
lower_letters[i]=d;
}
for(i=0;i<how_many;i++)
{
size=rand()%max+min;
for(j=0;j<size;j++)
{
temp=rand()%2;
letters=rand()%26;
if(temp==0)
 array_files[i][j]=upper_letters[letters];
else
 array_files[i][j]=lower_letters[letters];
 
}
array_files[i][size]='\0';
}
for(i=0;i<how_many;i++)
{
files[i]=open(array_files[i],O_RDONLY | O_CREAT | O_EXCL);
}
for(i=0;i<how_many;i++)
{
close(files[i]);
}
for(i=0;i<how_many;i++)
{
files[i]=open(array_files[i],O_WRONLY);
fstream file_class;
file_class.open(main_file);
while(!file_class.eof())
{
string tekst;
getline(file_class,tekst);
write(files[i],tekst.c_str(),1024);

}
}
for(i=0;i<how_many;i++)
{
close(files[i]);
}


printf("My new files:\n");
for(i=0;i<how_many;i++)
{
printf("%s",array_files[i]);
printf("\n");

}
}

};
int main(int argc, char** argv)
{
init_random();
New_files_copy Combat("new_files.cpp",10);

return 0;
}

Brak komentarzy:

Prześlij komentarz