简体   繁体   English

cmd参数中的语法错误

[英]error of syntax in the cmd parameters

#include<stdio.h>
#include<string.h>

char *operator[][10] = { {"(",")","[","]","->","."},
                    };

int main(int argc,int *argv[])
{   
    int len = sizeof(operator)/sizeof(operator[0][0]);

    for( int k = 1 ; k < argc ; k++ )
        printf("%s ",argv[k]);

    printf("\n");               

    for( int i = 0 ; i < 2 ; i++ )
    {
        for( int j = 0 ; j < 6 ; j++ )
        {
            for( int k = 1 ; k < argc ; k++ )
                if( !strcmp( argv[k],operator[i][j]) )
                    printf("%s",operator[i][j]);
        }
    }

    return 0;   
}

after compiled , I want to test if "->" is work,so I use command test.exe -> ,and it turns out a error of syntax.But when I change the command to test.exe "->" it works. 编译后,我想测试“->”是否正常工作,因此我使用命令test.exe -> ,结果发现语法错误。但是当我将命令更改为test.exe "->"它可以工作。 I wonder if it's about order syntax. 我想知道是否与顺序语法有关。 ps my OS is win7 and I use Dev-cpp. ps我的操作系统是win7,我使用Dev-cpp。 thanks for any help. 谢谢你的帮助。

> has special meaning to the command prompt, it's used to redirect output to a file. >在命令提示符下具有特殊含义,用于将输出重定向到文件。 You need to quote it to treat it literally. 您需要引用它才能按字面意义对待它。

BTW, I think this line in your program is wrong: 顺便说一句,我认为您程序中的这一行是错误的:

int len = sizeof(operator)/sizeof(operator[0][0]);

It should be: 它应该是:

int len = sizeof(operator)/sizeof(operator[0]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM