-4

I want to read argv[1] as char* so this is what I do

    using namespace std;
    const char *myarg = NULL;

void Plots(char* file);

int main( int size_t argc, char* argv[] ) {

        myarg = argv[1];
        cout<<"  this is a test "<<argv[1]<<endl;
        Plots(argv);
}


void Plots(char* fileList){

    cout<< argument passed correctly "<<endl;
            }

    }

However, when executing I get

Error: Function Plot() is not defined in current scope  :0:
Just_Newbie
  • 447
  • 1
  • 4
  • 11

1 Answers1

4

argv is a char *[], which for all practical purposes is char **.

You declared

void Plots(char * file);

The parameter to Plots() is a char *.

Plots(argv);

This attempts to pass a char ** to a function that takes char * as a parameter.

Additionally, although you declared

void Plots(char * file);

but then you went ahead and defined

void Plot(char* fileList)

Furthermore:

cout<< argument passed correctly "<<endl;

There's a quote missing here.

So, there's three different bugs here.

Sam Varshavchik
  • 114,536
  • 5
  • 94
  • 148
  • thanks - the typo in the quote was fixed . can you suggest how to make it work ie with a correct definition of Plots etc ? – Just_Newbie Jun 24 '16 at 11:17
  • @Just_Newbie Change the `Plots()` signature to `void Plots(char ** fileList);` The last pointer from the list is a `nullptr`. – πάντα ῥεῖ Jun 24 '16 at 11:38
  • It depends on what do you want to do. Do you need to pass a `char *` or a `char **`? Only you know how you make your own code work. – Sam Varshavchik Jun 24 '16 at 11:51
  • I only need to pass the argv as char *. Would be obliged if you could edit the initial code with the correct one. – Just_Newbie Jun 24 '16 at 12:14
  • You cannot "pass the argv" as `char *` because argv is a `char **`. Perhaps you need to pass argv[0], which would be a `char *`. Or maybe argv[1]. Who knows. Only you know what you want to do. – Sam Varshavchik Jun 24 '16 at 12:18