#: 14724 S3/Languages
30-Mar-92 10:15:10
Sb: #getkey problem in C
Fm: Robert A. Hengstebeck 76417,2751
To: all
Can someone help this poor frustrated fellow. I've been trying to get
a value returned from my getkey function to my main function, and I
have tried many ideas starting with using a 'return()' in the getkey.
I am getting the correct value from the 'printf' statement within the
getkey function, but when I print the value from the main function, I
consistently get some number like 19802 for both 'j' and 'vlu'. So
it seems that nothing is getting back up, unless the new value is a
pointer to the returned value - just a wild guess. The following
is a listing of what I have ended up after many trials. What do
you suggest?
** program name 'hello/c' **
#include
#option INLIB
int j, vlu;
main()
{
int i;
int getkey();
void clearsc();
void gotoxy();
clearsc();
printf("Enter a key when you are ready\n\n");
getkey(vlu);
j = vlu;
printf("vlu answer is %d, j answer is %d \n\n",vlu,j);
/* for(i = 0; i < j; i++)
{
gotoxy(i*2,i);
printf("This is my first program\n");
} */
}
void clearsc()
{
fputs("\x1c\x1f",stdout);
}
void gotoxy(col,row)
int col,row;
{
cursor(col,row);
}
int getkey(vlu)
{
while (TRUE)
{
vlu = inkey();
if (vlu != 0)
break;
}
printf(" the answer here is %d \n\n", vlu);
}
This program is being programmed on a Model IV computer, so if
there are any peculiarities, I have tried to avoid them. If I
seem to be making some silly code, please forgive me, since its
been three years since I last wrote in C.
There is 1 Reply.
|