The argv array is a list pointers, each pointing to the respective argument, with the first element the number of command line arguments, correct?
My question is how do I pass a string argument to a function? In this small example I'm just trying to print the text I write as argument in the command line.
#include <stdio.h>
#include <stdlib.h>
void ptest(char *);
int main(int argc, char const *argv[])
{
ptest(argv[1]);
return 0;
}
void ptest(char *ptr)
{
printf("%s\n", ptr);
}
This code does not compile. It gives the following compilation errors:
teste2.c:8:8: warning: passing 'const char *' to parameter of type 'char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
ptest(argv[1]);
^~~~~~~
teste2.c:4:18: note: passing argument to parameter here
void ptest(char *);
^