Sunday, September 27, 2009

oops posted the wrong io_display!

Posted the old one I was playing around with...the current one is this:

for (io_move(row, col), len<=0 ? len=strlen(str) : len; len > 0; len--, *str++) {
*str ? io_putch(*str) : io_putch(' ');
}

Still missing one space though...

io_display in one line

This does not fully work.
It's a success against cases where strlen(str) > len and len <= 0.
However when strlen(str) < len it fills up the remaining field with all but one space (eg. if str is "abc" and len is 6, it would only print "abc" plus 2 spaces). I've given up on it, at least for tonight.

for (io_move(row, col), len<=0 ? len=strlen(str) : len; len > 0; len--, *str++) {
len>0 && *str=='\0' ? io_putch(' ') : io_putch(*str);
}

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';
}