|
楼主 |
发表于 2006-12-24 01:03:20
|
显示全部楼层
谢谢楼上,用楼上的意见写的代码,希望指点:
#include <string.h>
#include <stdio.h>
main()
{
FILE *fp;
char buffer[1024*5];
size_t bytesRead;
char *match;
char model_name[40];
fp = fopen("/proc/cpuinfo","r");
if (fp == 0)
{
printf("open /proc/cpuinfo file error\n");
return 0;
}
bytesRead = fread(buffer, 1, sizeof(buffer),fp);
fclose(fp);
if (bytesRead == 0 || bytesRead == sizeof(buffer))
{
printf("readBytes NULL OR large than buffer \n");
return 0;
}
buffer[bytesRead] = '\0';
match = strstr (buffer, "model name");
if (match == NULL)
{
printf("match error\n");
return 0;
}
sscanf (match ,"model name : %50[^\n]", &model_name);
printf( "model name :%s\n",model_name);
return 0;
}
|
|