-
cant find bugs
just wondering if anyone can help with fixing the bugs in this prog... cant seem to fix them.
Code:
#include <stdio.h>
#include "put_row.h"
int main (int argc, char* argv[]) {
int start = 10;
int stop = 0;
int step = 1;
int c;
if (argc > 1) {
start = atoi(argv[1]);
}
if (argc > 2) {
stop = atoi(argv[2]);
}
if (argc > 3) {
step = atoi(argv[3]);
}
for (c = start; c > stop; c -= step) {
put_row(c, step, stop);
putchar('\n');
}
return 0;
Code:
#include <stdio.h>
#include "put_row.h"
void put_row(int start, int stop, int step) {
int c;
for (c = start; c != stop; c--) {
printf("%d ", c);
}
}
Code:
void put_row(int start, int stop, int step);
-
I cant really understand what the problem is but
one thing i can see is that you call put_row with wrong arguments
Code:
put_row(c, step, stop);
shouldnt it be:
Code:
put_row(c, stop, step);
??
-
forgot to say what i want the prog to do...
when you run the prog ie
% ./count 5 2
5 4 3
4 3
3
it currently prints the 2.
also its meant to step like this:
% ./count 9 3 2
9 7 5
7 5
5
any ideas?
-
Read RoD's suggestion.
Also,
>>for (c = start; c != stop; c--)
should be
>>for (c = start; c != stop; c -= step)
-
yep it works. thanks heaps guys.
-
You do know that you're including stdio.h twice, right?