Hardware information

How would I write a program in C that prints out the hardware the current computer has? And what about information about it?

Thank you for your time.

It depends on a lot of stuff. A c program under unix is at the mercy of the system call interface. Your version of unix may have some system calls that can get some of this. But they may not be documented and they may be available only to a root process. Or there may a special pseudo device. For example, under HP-UX, there are undocumented ioctl's which can be used with /dev/config. Even if your program is the kernel of your own operating system you may need an assist from assembler routines to do this. Or your os may have deposited everything into a text file and all you need to do is read that text file. So like I said, it depends...

The problem I have is actually getting anything from the OS about hardware.

I know for example typing "cat /proc/cpuinfo" in terminal will display the information about the CPU but how do I 'type' the command in C?

two ways:
call popen()

FILE *cmd=popen("cat /proc/cpuinfo");
char tmp[256]={0x0};
while(fgets(tmp,sizeof(tmp),cmd)!=NULL)
{
    printf("%s",tmp);
}
pclose(cmd)

Assuming you have Linux - linux/proc_fs.h is a header file for reading the /proc entries directly. See about the function pointer read_proc_t in the proc_dir_entry struct.

That is what I needed, thank you!