I am creating simple calculator. I give arguments to be calculated as command line arguments.
How do check if user gave no arguments at all?
I Tried this, but i get segmentation fault:
int main(int argc, char* argv[]){
if(argc == 0){
printf("No arguments were given");
return 0;
}
argcis the count of the program name and its arguments.When
argc == 1, there is only the program name and no additional arguments.It is possible for
argc == 0as that implies even the program name is not passed in.Test against 1
i get segmentation fault:
This is certainly due to unposted parts of OP's code.