请在下面找到我得到的代码和输出。
我的C代码在c:/turboc3/bin目录中
我的输出是在。
这是我正在编译的代码

#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;
}

输出为:
Illegal command: GETMAC.

有人能引导我通过这个吗?

最佳答案

非法命令:GETMAC意味着它试图运行它,但不能。
首先,要解决的问题是:记住在字符串中转义。不要使用/作为路径分隔符。
然后,尝试的东西,按近似顺序:尝试用GATMAC的完整路径。尝试不重定向。尝试不同的程序。将GETMAC包装到bat文件中,这将执行重定向。

关于c - 如何清除C语言的getmac程序中的错误?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13206623/

10-11 21:18