#include <iostream>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
using namespace std;
bool is_First(int value)
{
int i,sum;
sum=0;
for(i=1;i<value+1;i++)
if(value%i==0)
++sum;
if(sum==2)
return true;
else
return false;
}
int *first_Value;
char *text_Buffer;
char *read_Buffer;
void init_Values()
{
first_Value=new int[1000];
int i,j;
i=0;
j=2;
do
{
if(is_First(j))
{
first_Value[i]=j;
++i;
}
++j;
}while(i<1000);
}
void init_Buffer()
{
text_Buffer=new char[10000];
int i;
for(i=0;i<1000;i++)
snprintf(text_Buffer,sizeof(text_Buffer),"%d",first_Value[i]);
}
size_t size_files;
size_t *size_read;
int main(int argc, char **argv)
{
size_files=2048;
size_read=new size_t[2048];
init_Values();
init_Buffer();
int temp_file;
int read_file;
char temp_location[]="/tmp/first_values.XXXXXX";
temp_file=mkstemp(temp_location);
unlink(temp_location);
write(temp_file,&size_files,sizeof(size_files));
write(temp_file,text_Buffer,size_files);
read_file=open(temp_location,O_RDONLY);
lseek(read_file,0,SEEK_SET);
read(read_file,size_read,sizeof(*size_read));
read_Buffer=(char*) malloc(*size_read);
close(read_file);
delete first_Value;
delete text_Buffer;
return 0;
}
Brak komentarzy:
Prześlij komentarz