Is there a right way to call a char array and a char pointer to go to a function but it's pass by reference where it will also be manipulated?
Something like this:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void manipulateStrings(char *string1, char *string2[])
{
strcpy (string1, "Apple");
strcpy (string2, "Banana");
printf ("2 string1: %s", string1);
printf ("2 string2: %s", &string2);
}
int main ()
{
char *stringA;
char stringB[1024];
stringA = (char *) malloc ( 1024 + 1 );
strcpy (stringA, "Alpha");
strcpy (stringB, "Bravo");
printf ("1 stringA: %s", stringA);
printf ("1 stringB: %s", stringB);
manipulateStrings(stringA, stringB);
printf ("3 stringA: %s", stringA);
printf ("3 stringB: %s", stringB);
return 0;
}
I am not sure if I'm understanding correctly how to pass such variables to a function and change the values of those variables who happen to be char / strings
Edit: My question is - How would you be able to change the values of the two strings in the function?