In the code I am converting every character to '(' if the appears only once in the whole string, or to ')' if it appears more than once. I pass almost all tests, except the test with input "$$\". It gives "missing terminating character" error. I see that problem is the '\' char. and if I add a second '\' it is good, but is there a quick way to fix it, or I should somehow add 1 to the size of the pointer and then add the second '\'?
P.S. The input is fixed. I cannot change it.
char text[] = "$$\";
char *res = malloc(strlen(text));
int counter = 0;
for(int i = 0; i < strlen(text); i++) {
for(int j = 0; j < strlen(text); j++) {
if( tolower(text[i]) == tolower(text[j]) ) {
counter++;
}
}
if(counter == 1) {
res[i] = '(';
} else {
res[i] = ')';
}
printf("%c", res[i]);
counter = 0;
}
return 0;