C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 3rd, 2012, 05:10 AM
embed_ware embed_ware is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 2 embed_ware User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 45 m 40 sec
Reputation 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?

Reply With Quote
  #2  
Old November 3rd, 2012, 05:14 AM
bdb bdb is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 156 bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 15 h 48 m 11 sec
Reputation Power: 32
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

Reply With Quote
  #3  
Old November 3rd, 2012, 06:00 AM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,838 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 2 Days 17 h 58 m 15 sec
Reputation Power: 1774
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

Reply With Quote
  #4  
Old November 3rd, 2012, 06:15 AM
embed_ware embed_ware is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 2 embed_ware User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 45 m 40 sec
Reputation 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

Reply With Quote
  #5  
Old November 3rd, 2012, 06:34 AM
bdb bdb is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 156 bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level)bdb User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 15 h 48 m 11 sec
Reputation Power: 32
Quote:
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");

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > How to remove errors in getmac program in C language?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap