I'm very new to C and i'm trying to implement a call by reference procedure. Basically i want to have a string passed to function to be modified and for this modification to be reflected in the main() function. Here's the program i have right now but i get the error.
gcc -Wall -pedantic -c test.c
test.c: In function `main':
test.c:13: warning: passing arg 1 of `printString' from incompatible pointer type
gcc -Wall -pedantic test.o -ll -o test
Can anyone tell me what's happening here and how to correct it. Here's my program
#include <stdio.h>
#include <stdlib.h>
#include "test.h"
int main()
{
char* p;
p = malloc(sizeof(char));
p = "a";
printf("the pointer p conatins %s before calling printString\n", p);
printString(&p);
printf("Back in the main function p is %s\n", p);
return EXIT_SUCCESS;
}
void printString(char* s)
{
s = "b";
printf("In the printString function the pointer p contains %s\n", s);
}
gcc -Wall -pedantic -c test.c
test.c: In function `main':
test.c:13: warning: passing arg 1 of `printString' from incompatible pointer type
gcc -Wall -pedantic test.o -ll -o test
Can anyone tell me what's happening here and how to correct it. Here's my program
#include <stdio.h>
#include <stdlib.h>
#include "test.h"
int main()
{
char* p;
p = malloc(sizeof(char));
p = "a";
printf("the pointer p conatins %s before calling printString\n", p);
printString(&p);
printf("Back in the main function p is %s\n", p);
return EXIT_SUCCESS;
}
void printString(char* s)
{
s = "b";
printf("In the printString function the pointer p contains %s\n", s);
}