but it has many error:
46 C:\Program Files\DEV-CPP\main.cpp `sout' was not declared in this scope
47 C:\Program Files\DEV-CPP\main.cpp expected constructor, destructor, or type conversion before '<<' token
47 C:\Program Files\DEV-CPP\main.cpp expected `,' or `;' before '<<' token
48 C:\Program Files\DEV-CPP\main.cpp expected constructor, destructor, or type conversion before '.' token
48C:\Program Files\DEV-CPP\main.cpp expected `,' or `;' before '.' token
49 C:\Program Files\DEV-CPP\main.cpp expected constructor, destructor, or type conversion before '.' token
50 C:\Program Files\DEV-CPP\main.cpp expected declaration before '}' token
That's because buffer is destroyed at the end of the function, the memory is freeing, and now p point to garbage.
To fix that, either you allocate buffer dynamical, or use strcpy instead of assignment (make sure that s1 has enough space).
char *hex2dec(char *str, char * &p){ //changing the value of p
char *buffer = newchar[6]; //dynamic allocate space
//...
p = buffer;
}
int main(){
char *s1;
//...
hex2dec(s, s1);
//...
return 0;
}