Error...help...

Postby Emprise on Wed Jan 11, 2006 9:37 am

// gen
@cid "Gene";
@name "Gen";
@dbname "Gen";
@category "Utilities";
@ver "1.0";
main() {
int i,j,h,w;
int no[44];

do
{
gets(w);
if (w == 100)
{
for (i = 1 ; i <= 44; i++)
no[i] = i;
j = 44;
}
h = random( j ) + 1;
puts(":"+no[h]+"\n");
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:
100:initialize+gen
99:gen then exit
other value:gen
Emprise
 
Posts: 1
Joined: Wed Jan 11, 2006 9:30 am

Postby DeMue on Thu Jan 19, 2006 4:05 pm

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.
DeMue
 
Posts: 2
Joined: Thu Jan 19, 2006 4:48 am
Location: Germany

Postby DeMue on Thu Jan 19, 2006 4:07 pm

Sorry,

"gets is not a procedure but a function" would be better ;-)
DeMue
 
Posts: 2
Joined: Thu Jan 19, 2006 4:48 am
Location: Germany


Return to PocketC for Palm OS KB

Who is online

Users browsing this forum: No registered users and 1 guest

cron