I am Converting a C++ code into C program. I come across a function that takes void draw(char *&a). how to write this function *& in C program. I tried using same *&a but it is showing , (...etc expected. Please help. Thanks
Asked
Active
Viewed 818 times
1 Answers
6
There is no pass by reference in C. Therefore you need to change the function declaration to
void draw(char **a)

haccks
- 104,019
- 25
- 176
- 264
-
I changed function declaration to void draw(char **a) but its showing expected 'char **' but argument is of type 'char *' – karan Oct 02 '14 at 14:36
-
-
void towardDraw(char **a){ draw(a)}; void draw(char **ai){ int a,b,c,d,index=1000,i=1; FILE *f; f=fopen(ai, "r");} – karan Oct 02 '14 at 15:20
-
-
-
@karan: You'll need to add `&` to the function call to pass a pointer rather than a reference. So if the C++ does `draw(p)` for some `char * p`, then C will need `draw(&p)`. – Mike Seymour Oct 02 '14 at 17:08
-
1@karan: And also dereference the pointer when you use it in that function, to get the `char*` it points to. So in the code you've posted, `fopen(*ai, "r");`. Although, if the function doesn't need to modify the argument, then it should just take it by value, `char *a`, in both languages. – Mike Seymour Oct 02 '14 at 17:10