jeudi 26 janvier 2017

Evaluation of expressions like if( argv[1][0] != ~'t')

I have to input a string to make the second if condition false and print "Correct!". Can it be done?

#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[]) {

 if(argc != 2) { // argc is how long argv is, including that path-to-self
     puts("You need to give me exactly one argument!");
     return -1;

   }
// argv[1] represents the command line input you have given to the program. Which is a string or a char array.

 if(argv[1][0] != ~'t' || argv[1][1] != ~'h' || argv[1][2] != ~'e') {
      puts("noooo!");
      return 0;
    }
 else printf("Correct!\n");

 return 0;
}

Aucun commentaire:

Enregistrer un commentaire