#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
class my_CPU_value
{
private:
char *text_speed_Mhz;
char *text_cache_size;
char *text_name;
float value_Mhz;
int cache_size;
char model_name[96];
char my_buffer[4096];
FILE *init_file;
size_t value_read;
public:
my_CPU_value()
{
init_file=fopen("/proc/cpuinfo","r");
value_read=fread(my_buffer,1,sizeof(my_buffer),init_file);
fclose(init_file);
my_buffer[value_read]='\0';
text_speed_Mhz=strstr(my_buffer,"cpu MHz");
sscanf(text_speed_Mhz,"cpu MHz : %f",&value_Mhz);
text_cache_size=strstr(my_buffer, "cache size");
sscanf(text_cache_size,"cache size : %d",&cache_size);
text_name=strstr(my_buffer, "model name");
sscanf(text_name,"model name : %s",model_name);
}
void Write()
{
cout<<"Speed CPU = "<<value_Mhz<<" MHz"<<endl;
cout<<"Cache size = "<<cache_size<<endl;
cout<<"Model = "<<model_name<<endl;
}
};
int main(int argc, char **argv)
{
my_CPU_value C1;
C1.Write();
return 0;
}
Brak komentarzy:
Prześlij komentarz