whohasfriends3
whohasfriends3

Reputation: 15

C: how to return main usage?

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

Answers (1)

Jabberwocky
Jabberwocky

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

Related Questions