The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
How to remove errors in getmac program in C language?
Discuss How to remove errors in getmac program in C language? in the C Programming forum on Dev Shed. How to remove errors in getmac program in C language? C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 3rd, 2012, 05:10 AM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 2
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?
|

November 3rd, 2012, 05:14 AM
|
|
|
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
|

November 3rd, 2012, 06:00 AM
|
 |
Contributed User
|
|
|
|
|

November 3rd, 2012, 06:15 AM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 2
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
|

November 3rd, 2012, 06:34 AM
|
|
|
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");
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|