Folks, need to search through a character array and replace any occurrence of '+','/',or'=' with '%2B','%2F', and '%2F' respectively
base64output variable looks like
FtCPpza+Z0FASDFvfgtoCZg5zRI=
code
char *signature = replace_char(base64output, "+", "%2B");
signature = replace_char(signature, "/", "%2F");
signature = replace_char(signature, "=", "%3B");
char replace_char (char *s, char find, char replace) {
while (*s != 0) {
if (*s == find)
*s = replace;
s++;
}
return s;
}
(Errors out with)
s.c:266: warning: initialization makes pointer from integer without a cast
What am i doing wrong? Thanks!
base64output?const char *. As pointed out by RichardJ.RossIII '%2B' is not a character and maybe you need to pass it as string "%2B". So maybe your function should take inchar *, const char *, const char*. Also you have to make sure that your target string has enough memory to accommodate replacementchar* replace(char *, const char, const char*). What I am saying is that you should make sure thatsignatureis large enough to accommodate change for eg, if signature="hello+test" after change it will be "hello%2Btest" which is 2 more chars than before. So your function logic can a) assume that input string has enough memory allocated or b) takes care of this memory allocation. It is up to you to decide