I want to write a .c program using only libraries stdlib.h, stdio.h, and string.h. The program takes as input from the command line two words when the C program is is called - like this:
.mycode WORD1 WORD2
where WORD1 and WORD2 are both series of characters without spaces, forming a single word.
I want to store these two words in 2 char arrays in my code.
I also have to return a message to the user if more or less than EXACTLY 2 words are passed when the code was called.
Here is what I am trying:
int main(int argc, char *argv[])
{
//return error if user does not provide exactly two arguments
if(argc!=3)
{
printf("Wrong number of arguments. Please input: ./codename WORD1 WORD2");
exit(1);
}
char word1[]=argv[1];
char word2[]=argv[2];
I hoped that if i called the code: ./mycode hello goodbye
then, word1 will equal "hello" and word2 will equal "goodbye", but I get a compile error trying to do this: char word1[]=argv[1];