char * licenseKeyFormatting(char * S, int K){ int i,j=0,count=0,pst=0,n=0; int len = strlen(S); char* str = (char*)calloc(len*2,sizeof(char)); char* retStr = (char*)calloc(len*2,sizeof(char)); for (i=0; i<len; i++) { if (S[i] != '-') { if (S[i]>=97 && S[i]<=122) S[i] -= 32; str[pst++]=S[i]; } } count = pst % K; if (count == 0) count = K; while(*str) { n++; if (n == count+1) { retStr[j++] = '-'; n=0; count=K; continue; } retStr[j++] = *str++; } return retStr; }