Computer Science Canada Some trouble with my decreasing FOR loop. |
Author: | aaydee444 [ Fri Oct 02, 2009 3:24 pm ] | ||
Post subject: | Some trouble with my decreasing FOR loop. | ||
I have an assignment to convert numbers entered from a user to a different base. And I have the math part working, I know this because I spent a good portion of yesterday doing nothing but printf's. Here's my code
So basically the program compiles and runs but doesn't enter the for loop at the end. I'm pretty sure the logic is there but I'm not sure if I'm doing something that C accepts but is still wrong. The point of the For loop is to reverse the order of the array without moving any 0 values, like if the number in the 'temp' array is 00005432, i need it to be 00002345 instead. Also the 'num' variable is currently set to 500 as a test, it will be a user input. The value in the 'temp' array before the For loop is 00003131, and like i said before I need it to be 00001313. Any help would greatly be appreciated, also thank-you Antonio |
Author: | Zren [ Fri Oct 02, 2009 4:43 pm ] |
Post subject: | Re: Some trouble with my decreasing FOR loop. |
Why didn't I notice that first I'm not absolute with C, however don't for loops use variables (like i) as private. Thus your trying to redeclare something that already exists. I don't know what's up with C being weird. However Arrays start from 0; It wasn't working for me either however, I was running through you logic and found out this. Not sure if this was intended. |
Author: | aaydee444 [ Fri Oct 02, 2009 5:09 pm ] |
Post subject: | Re: Some trouble with my decreasing FOR loop. |
I see what your saying and thank-you, I had a few other errors that I now see. However, I don't think the FOR loop is executing at all, when I put a printf("blah blah blah"); it doesn't show up. Making me think that the swap that I'm trying to do isn't executing. |
Author: | md [ Fri Oct 02, 2009 10:34 pm ] |
Post subject: | RE:Some trouble with my decreasing FOR loop. |
The second element of your for loop is an assignment instead of a comparison. i=0 returns 0 which is false, and so the loop never runs. 'Tis an easy mistake to make; you learn to spot it quickly |
Author: | aaydee444 [ Tue Oct 06, 2009 3:19 pm ] |
Post subject: | Re: Some trouble with my decreasing FOR loop. |
thanks i found out i was going about my problem wrong, didn't even need the for loop in the end. |