#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
string yes_or_No(string value)
{
if(value=="1")
return "YES";
else
return "NO";
}
FILE* cd_FILE;
char buff_FILE[11][1024];
char **scanf_mat;
struct CD
{
string drive_name;
string drive_speed;
string open_tray;
string close_tray;
string lock_tray;
string write_cd_r;
string write_cd_rw;
string read_dvd;
string write_dvd_r;
string write_dvd_ram;
string select_disk;
};
size_t x_read[11];
int main(int argc, char **argv)
{
int i;
char d_Name[11][24];
struct CD cd_Info;
scanf_mat=new char*[11];
for(i=0;i<11;i++)
{
scanf_mat[i]=new char[1024];
}
for(i=0;i<11;i++)
{
cd_FILE=fopen("/proc/sys/dev/cdrom/info","r");
x_read[i]=fread(buff_FILE[i],1,sizeof(buff_FILE[i]),cd_FILE);
fclose(cd_FILE);
}
for(i=0;i<11;i++)
buff_FILE[i][x_read[i]]='\0';
scanf_mat[0]=strstr(buff_FILE[0],"drive name");
sscanf(scanf_mat[0],"drive name: %s",d_Name[0]);
cd_Info.drive_name=d_Name[0];
scanf_mat[1]=strstr(buff_FILE[1],"drive speed");
sscanf(scanf_mat[1],"drive speed: %s",d_Name[1]);
cd_Info.drive_speed=d_Name[1];
scanf_mat[2]=strstr(buff_FILE[2],"Can open tray");
sscanf(scanf_mat[2],"Can open tray: %s",d_Name[2]);
cd_Info.open_tray=yes_or_No(d_Name[2]);
scanf_mat[3]=strstr(buff_FILE[3],"Can close tray");
sscanf(scanf_mat[3],"Can close tray: %s",d_Name[3]);
cd_Info.close_tray=yes_or_No(d_Name[3]);
scanf_mat[4]=strstr(buff_FILE[4],"Can lock tray");
sscanf(scanf_mat[4],"Can lock tray: %s",d_Name[4]);
cd_Info.lock_tray=yes_or_No(d_Name[4]);
scanf_mat[5]=strstr(buff_FILE[5],"Can write CD-R");
sscanf(scanf_mat[5],"Can write CD-R: %s",d_Name[5]);
cd_Info.write_cd_r=yes_or_No(d_Name[5]);
scanf_mat[6]=strstr(buff_FILE[6],"Can write CD-RW");
sscanf(scanf_mat[6],"Can write CD-RW: %s",d_Name[6]);
cd_Info.write_cd_rw=yes_or_No(d_Name[6]);
scanf_mat[7]=strstr(buff_FILE[7],"Can read DVD");
sscanf(scanf_mat[7],"Can read DVD: %s",d_Name[7]);
cd_Info.read_dvd=yes_or_No(d_Name[7]);
scanf_mat[8]=strstr(buff_FILE[8],"Can write DVD-R");
sscanf(scanf_mat[8],"Can write DVD-R: %s",d_Name[8]);
cd_Info.write_dvd_r=yes_or_No(d_Name[8]);
scanf_mat[9]=strstr(buff_FILE[9],"Can write DVD-RAM");
sscanf(scanf_mat[9],"Can write DVD-RAM: %s",d_Name[9]);
cd_Info.write_dvd_ram=yes_or_No(d_Name[9]);
scanf_mat[10]=strstr(buff_FILE[10],"Can select disk");
sscanf(scanf_mat[10],"Can select disk: %s",d_Name[10]);
cd_Info.select_disk=yes_or_No(d_Name[10]);
cout<<"Name: "<<cd_Info.drive_name<<endl;
cout<<"Speed: "<<cd_Info.drive_speed<<endl;
cout<<"Can open tray: "<<cd_Info.open_tray<<endl;
cout<<"Can close tray: "<<cd_Info.close_tray<<endl;
cout<<"Can lock tray: "<<cd_Info.lock_tray<<endl;
cout<<"Can write CD-R: "<<cd_Info.write_cd_r<<endl;
cout<<"Can write CD-RW: "<<cd_Info.write_cd_rw<<endl;
cout<<"Can read DVD: "<<cd_Info.read_dvd<<endl;
cout<<"Can write DVD-R: "<<cd_Info.write_dvd_r<<endl;
cout<<"Can write DVD-RAM: "<<cd_Info.write_dvd_ram<<endl;
cout<<"Can select disk: "<<cd_Info.select_disk<<endl;
return 0;
}
sobota, 31 sierpnia 2019
czwartek, 15 sierpnia 2019
Data in StrinGrid and files
New files created:
#define g_Size 10
private: // User declarations
int base_Tab[g_Size][g_Size];
int base_Tab2[g_Size][g_Size];
int zero_Tab[g_Size][g_Size];
int zero_Tab2[g_Size][g_Size];
int sum_Tab[g_Size][g_Size];
int sum_Tab2[g_Size][g_Size];
int Base[6][g_Size][g_Size];
UnicodeString string_Tab[g_Size][g_Size];
UnicodeString string_Tab2[g_Size][g_Size];
bool __fastcall is_First(int value);
UnicodeString __fastcall zero_One(int value);
AnsiString name_Files[6];
FILE *my_File[6];
void __fastcall init_Arrays();
{
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;
}
UnicodeString __fastcall TForm1::zero_One(int value)
{
UnicodeString result;
if(is_First(value))
result="1";
else
result="0";
return result;
}
void __fastcall TForm1::init_Arrays()
{
int i,j,k,l;
for(i=0;i<6;i++)
name_Files[i]="date"+IntToStr(i)+".txt";
k=1;
for(i=0;i<g_Size;i++)
{
for(j=0;j<g_Size;j++)
{
base_Tab[i][j]=k;
l=(i+1)*(j+1);
base_Tab2[i][j]=l;
base_Grid->Cells[j][i]=IntToStr(base_Tab[i][j]);
base_Grid2->Cells[j][i]=IntToStr(base_Tab2[i][j]);
if(is_First(k))
{
zero_Tab[i][j]=1;
string_Tab[i][j]="1";
}
else
{
zero_Tab[i][j]=0;
string_Tab[i][j]="0";
}
if(is_First(l))
{
zero_Tab2[i][j]=1;
string_Tab2[i][j]="1";
}
else
{
zero_Tab2[i][j]=0;
string_Tab2[i][j]="0";
}
Grid2->Cells[j][i]=string_Tab[i][j];
Grid4->Cells[j][i]=string_Tab2[i][j];
++k;
}
}
for(i=0;i<g_Size;i++)
{
for(j=0;j<g_Size;j++)
{
k=l=0;
if(i-1>-1)
{
k+=zero_Tab[i-1][j];
l+=zero_Tab2[i-1][j];
}
if(i-1>-1 && j-1>-1)
{
k+=zero_Tab[i-1][j-1];
l+=zero_Tab2[i-1][j-1];
}
if(j-1>-1)
{
k+=zero_Tab[i][j-1];
l+=zero_Tab2[i][j-1];
}
if(i+1<g_Size && j-1>-1)
{
k+=zero_Tab[i+1][j-1];
l+=zero_Tab2[i+1][j-1];
}
if(i+1<g_Size)
{
k+=zero_Tab[i+1][j];
l+=zero_Tab2[i+1][j];
}
if(i+1<g_Size && j+1<g_Size)
{
k+=zero_Tab[i+1][j+1];
l+=zero_Tab2[i+1][j+1];
}
if(j+1<g_Size)
{
k+=zero_Tab[i][j+1];
l+=zero_Tab2[i][j+1];
}
if(i-1>-1 && j+1<g_Size)
{
k+=zero_Tab[i-1][j+1];
l+=zero_Tab2[i-1][j+1];
}
k+=zero_Tab[i][j];
l+=zero_Tab2[i][j];
sum_Tab[i][j]=k;
sum_Tab2[i][j]=l;
Grid1->Cells[j][i]=IntToStr(sum_Tab[i][j]);
Grid3->Cells[j][i]=IntToStr(sum_Tab2[i][j]);
}
}
for(i=0;i<g_Size;i++)
{
for(j=0;j<g_Size;j++)
{
Base[0][i][j]=base_Tab[i][j];
Base[1][i][j]=base_Tab2[i][j];
Base[2][i][j]=zero_Tab[i][j];
Base[3][i][j]=zero_Tab2[i][j];
Base[4][i][j]=sum_Tab[i][j];
Base[5][i][j]=sum_Tab2[i][j];
}
}
for(i=0;i<6;i++)
{
my_File[i]=fopen(name_Files[i].c_str(),"w");
for(j=0;j<g_Size;j++)
{
for(k=0;k<g_Size;k++)
{
fprintf(my_File[i],"%d",Base[i][j][k]);
fprintf(my_File[i],"\n");
}
}
}
for(i=0;i<6;i++)
{
fclose(my_File[i]);
}
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
init_Arrays();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Close();
}
niedziela, 4 sierpnia 2019
Using environ. Linux C++
#include <iostream>
#include <string.h>
#include <fstream>
#include <stdio.h>
using namespace std;
class ENV
{
private:
char **temp_Text;
char *file_Name;
public:
char **environ;
ENV(char *f_Name)
{
strcpy(file_Name,f_Name);
}
void Write()
{
fstream my_File(file_Name,ios::out);
for(temp_Text=environ;*temp_Text!=NULL;++temp_Text)
{
my_File<<*temp_Text<<endl;
my_File.flush();
}
my_File.close();
}
};
int main(int argc, char **argv)
{
ENV testEnv("date_Env2");
testEnv.Write();
return 0;
}
And next: vim date_Env2
#include <string.h>
#include <fstream>
#include <stdio.h>
using namespace std;
class ENV
{
private:
char **temp_Text;
char *file_Name;
public:
char **environ;
ENV(char *f_Name)
{
strcpy(file_Name,f_Name);
}
void Write()
{
fstream my_File(file_Name,ios::out);
for(temp_Text=environ;*temp_Text!=NULL;++temp_Text)
{
my_File<<*temp_Text<<endl;
my_File.flush();
}
my_File.close();
}
};
int main(int argc, char **argv)
{
ENV testEnv("date_Env2");
testEnv.Write();
return 0;
}
And next: vim date_Env2
Subskrybuj:
Posty (Atom)