dimanche 27 septembre 2020

Argument total (in argc) shows different number while printing in an if statement in C?

I am having a tough time because this just makes no sense. I am not sure if it is a compiler issue or not but here is a snip it of my main function and during the print of argc within the if and outside of the if statements are different numbers. Within the if statement it is always 3, even when there are 7 arguments...anyway anyone can make sense of this??

void main (int argc, char *argv[]){
    int rowsSize;
    int colsSize;
    int totalArgs;
    totalArgs = argc;

    rowsSize = atoi( argv[1]);
    colsSize = atoi( argv[2]);
    int table[rowsSize][colsSize];
    int indexTable[rowsSize];
    float freqTable[rowsSize];

    printf("%d \n", argc);
    printf("%d \n", totalArgs)

    if(totalArgs = 3){

            if(rowsSize >= 5 && rowsSize <= 20 ){
                    if(colsSize >= 5 && colsSize <= 20 ){

                            printf("total args should be 3 %d \n",totalArgs);
                        
                    }

}}}

Aucun commentaire:

Enregistrer un commentaire