0

I want to get the MAC address of my PC and assign it to a variable.

I have already tried this code and it outputs the address but I don't know how to assign it to a variable. Also I don't want to prompt anything.

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

int main()
{
    system("getmac");
    getch();
    return 0;
}
  • As @doptimusprimes answer indicates, there are other ways to get the mac address. But if you want to read the output of a system call, that question is already asked and answered on SO several times. e.g. https://stackoverflow.com/questions/43116/how-can-i-run-an-external-program-from-c-and-parse-its-output – visibleman Oct 30 '19 at 07:18

1 Answers1

0

Welcome to the world of programming. You need to use Win32 or system level API to get MAC address. You can read more on MSDN especially about winsock and use that to find MAC address.

Also refer https://social.msdn.microsoft.com/Forums/vstudio/en-US/ed1f0702-cb8a-4795-a512-667f1cf4617b/how-to-get-the-mac-address-of-local-computer-?forum=vcgeneral

Read doc here: https://learn.microsoft.com/en-us/windows/win32/winsock/windows-sockets-start-page-2

doptimusprime
  • 9,115
  • 6
  • 52
  • 90