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
#include <stdio.h>
#include <conio.h>
#include <string.h>
int main ()
{
//char mac[200];
FILE *fp;
clrscr();
// fp=fopen("c:\macid.txt","w");
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?
Illegal command: GETMAC implies, that it tries to run it but can't.
First, things to fix : Remember to escape \\ inside string. Do not use / as path separator.
Then, Things to try, in approximate order: Try with full path to GETMAC. Try without redirection. Try with different program. Wrap GETMAC into bat file, which does the redirection.
I am not sure how your file macid.txt resides in c:/turboc3/disk
, but - I think you can solve this problem by giving a full path to the system()
function call.
LIke this:
system("c:/windows/system32/getmac.exe > macid.txt");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.