The variable p
is declared as having the type char[10]
char p[10]="ravi";
So the expression &p
in this call
mystrcat(&p, q);
has the type char ( * )[10]
.
However the corresponding function parameter has the type char **
.
void mystrcat(char **p, char *q)
and there is no implicit conversion from the type char ( * )[10]
to the type char **
. So the compiler issues an error.
You could call your function the following way
char *tmp = p;
mystrcat( &tmp, q );
But in any case the function is incorrect at least due to this while loop
while(**p != '\0')
{
*p++;
}
because the expression
*p++
is equivalent to the expression
*( p++ )
while you need the expression
( *p )++
or
++*p
Or the last statement shall be
**p = '\0';
instead of
*p = '\0';
There is no any sense to declare the first function parameter as having the type char **
instead of the type char *
as it is declared in the standard C function strcat
.
char * strcat(char * restrict s1, const char * restrict s2);
Moreover the second parameter shall have the qualifier const
because the corresponding string is not changed within the function. And the function should return a pointer to the destination string.
So the function can look the following way
char * mystrcat( char *p, const char *q )
{
char *s = p;
while ( *s ) ++s;
while ( ( *s++ = *q ) != '\0' ) ++q;
return p;
}
and be called like
puts( mystrcat( p, q ) );
Here is a demonstrative program.
#include <stdio.h>
char * mystrcat( char *p, const char *q )
{
char *s = p;
while ( *s ) ++s;
while ( ( *s++ = *q ) != '\0' ) ++q;
return p;
}
int main(void)
{
char p[10] = "ravi";
char q[12] = "ra";
puts( mystrcat( p, q ) );
return 0;
}
The program output is
ravira