i need help with one problem in C. I have two numbers. First is "number string" (i represent it in string), i need to split it to any combination of numbers those sum of them give me second number. For example : 888 24 I need to split it into 8 + 8 + 8 The returned number is count of + elements. In example is answer 2. Split it into every one digit is easy but i dont know how to do it in different cases.
1234 46 (12+34)
1234 127 (123+4)
101 2 (1+01)
When i dont find any combination returned value is IMPOSSIBLE.
i have this to split string into numbers but i dont know how apply it successfully :/
long** printComb(char *line, int l, int lp, int r, int rp){
char **vys;
vys = (char**) malloc(2*sizeof(char*));
vys[0] = (char*) malloc(lp*sizeof(char));
vys[1] = (char*) malloc(rp*sizeof(char));
int i;
for(i = 0; i < lp; i++)
vys[0][i] = line[l+i];
vys[0][i] = '\0';
for(i = 0; i < rp; i++)
vys[1][i] = line[r+i];
vys[1][i] = '\0';
return vys;
}
Thanks for every advice :)