wtorek, 30 marca 2021

Save time to file (C/C++)

 #include <sys/time.h>

#include <iostream>

#include <unistd.h>

#include <time.h>

#include <string.h>

#include <fstream>

using namespace std;


class print_Time

{

private:

char print_Day[64];

char print_Year[64];

struct tm* loctime;

struct timeval gettime;

public:

print_Time()

{

gettimeofday(&gettime,NULL);

loctime=localtime(&gettime.tv_sec);

}

void save_Day(string file_Name)

{

strftime(print_Day,sizeof(print_Day),"%D-%m-%y %S:%M:%H",loctime);

ofstream my_File;

my_File.open(file_Name.c_str());

my_File<<print_Day;

my_File.close();

}

void save_Year(string file_Name)

{

strftime(print_Year,sizeof(print_Year),"%Y-%m-%d %H:%M:%S",loctime);

ofstream my_File;

my_File.open(file_Name.c_str());

my_File<<print_Year;

my_File.close();

}

};




int main(int argc, char **argv)

{

string dataD="dataDay.txt";

string dataY="dataYear.txt";

print_Time *p_Time=new class print_Time;

p_Time->save_Day(dataD);

p_Time->save_Year(dataY);

delete [] p_Time;

return 0;

}


piątek, 12 marca 2021

Reading diagnostic files in Windows 10 (C/C++)

 #include <iostream>

#include <fstream>

#include <conio.h>

#include <string.h>

#include <unistd.h>

#include <stdio.h>

#include <fcntl.h>


using namespace std;

#define m_F 5

#define size_F 2048

char *read_File(const char *name)

{

    ssize_t b_Read;

    char* buff;

    int file;

    buff=new char[size_F];

    if(buff==NULL)

        return NULL;

    file=open(name,O_RDONLY);

    b_Read=read(file,buff,size_F);

    close(file);

    return buff;

}

string winFiles[m_F]={"DtcInstall.log","PFRO.log","Synaptics.log",

 "Synaptics.PD.log","WindowsUpdate.log"};

string win_Path="C:\Windows\\";

string new_Files[m_F];

char **Buffer;


int main()

{

    int i;

    Buffer=new char* [m_F];

    for(i=0;i<m_F;i++)

        Buffer[i]=new char[size_F];


    for(i=0;i<m_F;i++)

        new_Files[i]=win_Path+winFiles[i];

    for(i=0;i<m_F;i++)

    {

        strcpy(Buffer[i],read_File(new_Files[i].c_str()));

    }


     fstream main_File( "Diagnostic.txt", ios::out );

     if(main_File.good())

     {

         for(i=0;i<m_F;i++)

         {

             main_File<<Buffer[i];

             main_File.flush();

         }

         main_File.close();

     }


    for(i=0;i<m_F;i++)

        delete [] Buffer[i];

    delete [] Buffer;


    getch();

    return 0;

}