0

My instructions are pretty clear, but I'm doing it wrong, can you help correct my error?

Instructions: else if (“pwd”) declare a char variable array of size MAX_PATH_LENGTH to hold the path do a getcwd print the path

my code:

 }else if(strcmp(argv[0],"pwd")){
        char arr[MAX_PATH_LENGTH];
        char getcwd(arr,MAX_PATH_LENGTH);
        printf("cwd: %s",arr); 
TeSa
  • 37
  • 1
  • 8
  • 2
    `char getcwd(arr,MAX_PATH_LENGTH);` => `getcwd(arr, MAX_PATH_LENGTH);`. Also you should check the return value before printing the value. – Sergej Christoforov Apr 20 '17 at 08:51
  • 2
    `if(strcmp(argv[0],"pwd"))` means "if the strings are unequal". And I wonder where `argv[0]` comes from. If it is an argument of `main` then `argv[0]` is the executable's name. – Weather Vane Apr 20 '17 at 08:51
  • What do you intend to do at this line char getcwd(arr,MAX_PATH_LENGTH); ?? – Mohammed Bakr Sikal Apr 20 '17 at 08:56
  • Please post code that actually compiles. The line `char getcwd(arr,MAX_PATH_LENGTH);` is a function declaration, that is missing the parameter types, not a call to the function. – JeremyP Apr 20 '17 at 08:56
  • thank you @willys that was my error. – TeSa Apr 20 '17 at 09:01

1 Answers1

3

strcmp returns an integer and not a boolean.

int strcmp (const char* str1, const char* str2);

It returns a 0 if the two strings are equal, so you should be checking the returned value in your if statement like this:

if(strcmp(argv[0],"pwd")==0)