I'm trying to pass two strings to a function that copies the second string into the first string. Get the error messages
"passing arguement 1/2 of 'CopyStrings'from incompatible pointer type - line 25.
note: expected 'char*' but argument is of type 'char**' - line 8
Here is my code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
// a function that gets 2 strings and copies the second one into the first one
char CopyStrings(char* string1, char* string2)
{
strcpy(string1, string2);
return *string1;
}
int main()
{
char* string1 = (char*)malloc(sizeof(char)*10);
char* string2 = (char*)malloc(sizeof(char)*10);
strcpy(string1, "ugabuga");
strcpy(string2, "mukaluka");
printf("%s", CopyStrings(string1, string2));
free(string1);
free(string2);
return 0;
}
Any suggestions what I messed up and how I write the pointers correctly?
EDIT - Now that I changed
(&string1, &string2)
into
(string1, string2)
the program chrashes.