Page 1 of 1

PostPosted: Wed Jan 11, 2006 9:37 am
by Emprise
// gen
@cid "Gene";
@name "Gen";
@dbname "Gen";
@category "Utilities";
@ver "1.0";
main() {
int i,j,h,w;
int no[44];

if (w == 100)
for (i = 1 ; i <= 44; i++)
no[i] = i;
j = 44;
h = random( j ) + 1;
for (i = h; i < j; i++)
no[i] = no[i+1];
j = j - 1;
if (j == 0)
puts("All generated!!");
while (w != 99);

this is my source code...but i can run it properly, can anyone help me...actually i dun know C at all...i translate pascal to it...
my logic:
read a integer (w);
if w is 100 then assign started value
gen a number
shorten range and elimilate appeared one...
if w is 99 then exit...

that mean, enter:
99:gen then exit
other value:gen

PostPosted: Thu Jan 19, 2006 4:05 pm
by DeMue
Well, i am not quite sure what you intend to do, but as far as i can see you have three problems:

- gets is not a function but a procedure. You have to use w = gets(w);
- int no[44] declares an array from no[0] to no[43], but your init-loop
runs from no[1] to no[44].
- random(0) is not defined and causes a runtime error. So you might
want to check for j==0 before calling it. Or perhaps you could exit
the loop when j reaches 0.

PostPosted: Thu Jan 19, 2006 4:07 pm
by DeMue

"gets is not a procedure but a function" would be better ;-)