Reputation: 15
So I have a function inside the main that just concatenates two strings passed into argument.
They are passed like this:
./main hello world
and will generate:
helloworld
But I need to have this when no arguments are passed:
./main
main: Usage: str1 str2
How can I do this ?
Upvotes: 0
Views: 48
Reputation: 50882
You probably want something like this:
...
int main(int argc, char *atgv[]) {
if (argc < 3) // argc = number of arguments including name of program
{
printf("Usage: main str1 str2\n");
return 1;
}
...
}
Upvotes: 1