how to capture OS name using C/C++ code

Hi,

I want to know the os name via c/c++ source code.so please help me to do the same.
I will appreciate if anyone can provide me the source code.

Thanks in advance..

man uname(2)

Ok, so here's the source:

#include <stdio.h>
#include <sys/utsname.h>
#include <stdlib.h>

int main()
{
	struct utsname name;
	if(uname(&name)) exit(-1);
	printf("Your computer's OS is %s@%s\n", name.sysname, name.release);
	return 0;
}

So should I forward my bank connection to you?

on which system it works.
on Windows its giving

#include <sys/utsname.h>

is not present.

Here is a clue:

uts = Unix Time-sharing System

yeah,its working.

can you also tell us how this can be done on windows.
we need to know the structure name/ header file probably to print the OS details.

do we have any portable code which prints the OS name regardless of the OS we are using.

thanks.

There is no universally portable way to retrieve the name of the OS.

If you are looking for answers to questions relating to Microsoft Windows, you should ask such questions in a Windows-related forum.

It seems Windows GetVersionEx function is what you want.

If you want to know only OS is linux/Windows, this will help you.

# include <stdio.h>

main ()
{
system("perl -e 'print $^O;'");

}

Returns linux if the machine is running with linux. 'MSWin32' for windows.

The method to acquire the OS name isn't platform-portable, and the C or C++ code is. This by itself will cause you endless problems.

Try using "system()" and a platform-specific call to get this information. After a failure you can try another way. But you will certainly not find a way to do this without regard to platform -- ironically enough.