I am trying to replace a string in a function with double pointers. I would like to see this change back in main. What am I doing wrong?
These are the warnings my compiler gave me.
$ gcc *.c -Wall
main.c: In function ‘replacevalue’:
main.c:10:12: warning: passing argument 1 of ‘strcpy’ makes pointer from integer without a cast [-Wint-conversion]
strcpy(**pinput1, string);
^
In file included from main.c:4:0:
/usr/include/string.h:38:8: note: expected ‘char * restrict’ but argument is of type ‘char’
char *strcpy (char *__restrict, const char *__restrict);
^~~~~~
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
void replacevalue(char **pinput1)
{
char string[] = "here is the replacement string";
strcpy(**pinput1, string);
}
void stringtest(char *pinput1)
{
replacevalue(&pinput1);
}
int main()
{
char string[] = "here is a string ";
char *pinput1 = string;
printf("%s \n", pinput1);
stringtest(pinput1);
printf("%s \n", pinput1);
return 0;
}//end main