What is the proper way to receive a command line argument from the user and compare it to a single char? For example if the user typed "Y" for yes run some function and "N" for no would run another function.
My main error is "comparison between ptr and integer" & "too few arguments to function call, expected 3 have 1"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void calculate();
void verify();
int main (int argc, char *argv[]) {
if(argc < 2){
printf("Please enter a mode of operation.\n");
return 0;
}
else if(argc > 2){
printf("Too many arguments supplied. Please try again.\n");
return 0;
}
else if(strncmp(argv[1] == 'c') == 0)
calculate();
else if(strncmp(argv[1] == 'v') == 0)
verify();
return 0;
}
void calculate(){
}
void verify(){
}
strncmp(argv[1] == 'c') == 0
-->strcmp(argv[1], "c") == 0
strncmp(argv[1] == 'c')
-->strncmp(argv[1], "c",1)
strncmp(argv[1], "c") == 0
to compare the argument to the stringc
if(*argv[1]=='c')
?