Saturday, September 19, 2009

My solution to OOP344 Challenge#1

Here's my solution, I have a feeling that it's a little more complicated than it needs to be but it works...If anyone can help me make it simpler I'd appreciate it. =)

void GetInt(char *strint, int val){
/* sprintf(strint,"%d", val); */
int i, valcpy = val, n = 1, j;
for (i=0; valcpy>0; i++) {
valcpy /= 10;
n *= 10;
}
n /= 10;
for (i,j=0; i>0 ; i--,j++) {
valcpy = val / n;
strint[j] = valcpy + 48;
val -= valcpy * n;
n /= 10;
}
strint[j] = '\0';
}

No comments:

Post a Comment