I keep having problems when I'm returning a string from my sub. It keeps printing:
CPU Type: Auth(????VB
CPU Model: AMD
when I print.
Here is my code:
Code:
char * GetCPUType()
{
FILE* fp;
char buffer[1024];
size_t readBytes;
char* CPUTypeMatch;
char* CPUType;
/* Read /proc/cpuinfo */
fp = fopen ("/proc/cpuinfo", "r");
readBytes = fread (buffer, 1, sizeof (buffer), fp);
fclose(fp);
/*quit if nothing is read */
if(readBytes==0 || readBytes == sizeof(buffer))
return EXIT_SUCCESS;
buffer[readBytes] = '\0';
/* Locate the CPU Type */
CPUTypeMatch = strstr(buffer,"vendor_id");
sscanf (CPUTypeMatch,"vendor_id : %s", &CPUType);
return CPUType;
}
int main(int argc, char *argv[])
{
char* CPUType;
char* CPUModel;
CPUType = GetCPUType();
CPUModel = GetCPUModel();
printf("CPU Type: %s \n", &CPUType);
printf("CPU Model: %s \n", &CPUModel);
return EXIT_SUCCESS;
}
Thank you!