So Challenge 1 GetInt function

October 5, 2009

ya I know it was late, but I just dont like to blog. Anyway there is my code for GetInt function:


void GetInt(char *strint, int val){
int i;
int t;

/*strint[1] = (val < 0 && (strint[0] = ‘-’ || val = (0 – val)));*/

strint[0] = ‘ ‘;
if(val < 0){ strint[0] = ‘-’; val = -val; }

strint[1] = 0;

if(val == 0){ strint[1] = Zero; strint[2] = 0; }

for(i=1; val != 0; i++){

for(t = i; t >= 1; t–){
strint[t+1] = strint[t];
}
strint[1] = val%10+Zero;
val = (val – val%10)/10;
}
}

I defined Zero to 48 which is ascII code for number 0

inside my code, there is a piece of that is commented. I tried to use that line of code to replace the negative checking part … but the compiler complained because I tried to use Boolean value False, which I know is 0 ,as the null byte for string end checking. I tried to put (int) in front of the Boolean value, but its not helping … anyone can help me out

First Time on Blogging

October 5, 2009

AsĀ  I said, it gonna take a while till I can get used to this stuff :)


Follow

Get every new post delivered to your Inbox.