Nibnat
Nibnat

Reputation: 13

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. I wonder if it's about order syntax. p.s my OS is win7 and I use Dev-cpp. thanks for any help.

Upvotes: 0

Views: 101

Answers (1)

Barmar
Barmar

Reputation: 781834

> 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]);

Upvotes: 3

Related Questions