Code:
char *conversionpointer = NULL;
char *chartodecimal(const char *STRING) // replaces all occurrences of char to html decimals
{
conversionpointer = (char *)realloc(conversionpointer, strlen(STRING) + 1);
strcpy(conversionpointer, STRING);
char original[15][3] = { "ç", "\"", "&", "ñ", "ä", "é", "ë", "ü", "ã", "º", "ª", "á", "ó", "ø", "ß"};
char replacement[15][7] = {"ç ;","" ;","& ;","ñ ;","ä ;","é ;","ë ;","ü ;","ã ;","º ;","ª ;","á ;","ó ;","ø ;","ß ;"};
char *conversionpointeroriginalp = NULL;
char *buffer = NULL;
int count = 0;
while(count < 15)
{
conversionpointeroriginalp = strstr(conversionpointer, original[count]);
while(conversionpointeroriginalp != NULL)
{
buffer = (char *)realloc(buffer, strlen(conversionpointer) + 1 + (strlen(replacement[count]) - strlen(original[count])));
strncpy(buffer, conversionpointer, (size_t)(conversionpointeroriginalp - conversionpointer));
sprintf(buffer + (conversionpointeroriginalp - conversionpointer), "%s%s", replacement[count], conversionpointeroriginalp + strlen(original[count]));
conversionpointer = (char *)realloc(conversionpointer, strlen(buffer) + 1);
strcpy(conversionpointer, buffer);
conversionpointeroriginalp = strstr(conversionpointeroriginalp, original[count]);
}
count++;
}
if (buffer != NULL)
{
free(buffer);
}
return conversionpointer;
}
int main(void)
{
printf("%s\n", chartodecimal("Barça"));
return 0;
}