#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    How to remove errors in getmac program in C language?


    Please find below the code and the output which I am getting.

    My C code is in c:/turboc3/bin directory and my output macid.txt is in c:/turboc3/disk.

    Here is the code which I am compiling

    Code:
    #include <stdio.h> 
             #include <conio.h> 
             #include <string.h> 
             int main () 
                { 
                  //char mac[200]; 
                  FILE *fp; clrscr(); 
                  system("GETMAC>c:/macid.txt");
                  fp=fopen("c:/macid.txt","r");
                  if(fp!=NULL) 
                        { 
                          char line[128]; 
                          while(fgets(line,sizeof line,fp)!=NULL) 
                                { 
                                      char *nwln=strchr(line,'\n');
                                      char *ptr; 
                                      if(nwln!=NULL) *nwln='\0'; 
                                      ptr=strstr(line,"Physical Address"); 
                                      if(ptr!=NULL)
                                            { 
                                              printf("%s\n",ptr); break; 
                                            } 
                               } 
                 } 
              getch(); 
              return 0;
     }
    The output is:

    Illegal command: GETMAC.
    Can anyone guide me through this?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    156
    Rep Power
    34
    Your immediate problem is here
    Code:
    system("GETMAC>c:/macid.txt");
    Last edited by bdb; November 3rd, 2012 at 06:29 AM. Reason: deleted text that was no longer relevant
  4. #3
  5. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,387
    Rep Power
    1871
    The other immediate problem is that you're running TurboC fossilware.

    Assuming for a moment that you can even get system() to work, what chance do you think it has of running a win32 executable when all it knows about are DOS .COM files and .EXE files?

    Get a compiler compatible with your real OS
    http://www.microsoft.com/express/Downloads/
    http://www.smorgasbordet.com/pellesc/
    http://www.codeblocks.org/
    http://sourceforge.net/projects/orwelldevcpp/
    Then you might be able to find the appropriate Win32 API to get your information, rather than resorting to the batch-script-hackery of calling system() to do every little thing for you.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    SYSTEM() Function works fine


    the system function works fine. if instead of getmac when i write DIR the same program works as desired i.e. it properly display all the included directories in the present working directory
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    156
    Rep Power
    34
    Originally Posted by embed_ware
    the system function works fine.
    Yes, the problem is the argument passed to system().

    the system() function works fine does not mean that it works fine with any and all arguments!
    Code:
    system("UNRECOGNIZED_COMMAND ...");
    Try and specifiy the full path to where GETMAC is
    Code:
    system("c:/tools/internet/example/GETMAC>c:/macid.txt");
    Also, if that fails, try with backslashes
    Code:
    system("c:\\tools\\internet\\example\\GETMAC>c:\\macid.txt");

IMN logo majestic logo threadwatch logo seochat tools logo