/ Forside / Teknologi / Udvikling / C/C++ / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
C/C++
#NavnPoint
BertelBra.. 2425
pmbruun 695
Master_of.. 501
jdjespers.. 500
kyllekylle 500
Bech_bb 500
scootergr.. 300
gibson 300
molokyle 287
10  strarup 270
Problem
Fra : Derek Winkler


Dato : 09-04-02 05:28

In the following bit of code, I have a slight problem. In my example, i is
0. When it gets to the switch and I press N, it prints "Type new name for
this item:" to the screen. However, when I go to start typing the new name,
nothing happens until I press N again, at which time it reprints the message
and lets me type in a name. After I type in the name, though, and hit ENTER,
the program locks up and I have to exit with CTRL+BREAK. If i is anything
other than 0, the program runs into an error and exits.

int i,b,a;
.. . . . . . (a few lines of printfs and stuff) . . . . . .
do {
switch(toupper(getch())) {
case 'N': printf("Type new name for this item: ");
gets(item[i].name);
break;
case 'P': printf("Enter Bidder's Number: ");
scanf("%d",&a);
item[i].bidder=a-1;
printf("Enter Price: ");
scanf("%d",&item[i].price);
break;
case 'C': return;
break;
}
} while(!(kbhit()));

It is awfully late, and I'm probably missing something obvious, but any help
you could offer would be greatly appreciated. thank you!



 
 
Anders Bo Rasmussen (09-04-2002)
Kommentar
Fra : Anders Bo Rasmussen


Dato : 09-04-02 11:09

On Tue, 09 Apr 2002 04:28:28 GMT,
Derek Winkler <dwinkler@NOSPAMcomcast.net> wrote:

> In the following bit of code, I have a slight problem. In my example, i is
> 0. When it gets to the switch and I press N, it prints "Type new name for
> this item:" to the screen. However, when I go to start typing the new name,
> nothing happens until I press N again, at which time it reprints the message
> and lets me type in a name. After I type in the name, though, and hit ENTER,
> the program locks up and I have to exit with CTRL+BREAK. If i is anything
> other than 0, the program runs into an error and exits.
>
> int i,b,a;
> . . . . . . (a few lines of printfs and stuff) . . . . . .
> do {
> switch(toupper(getch())) {

getch() blokerer vel, indtil der kommer et tegn.

> case 'N': printf("Type new name for this item: ");
> gets(item[i].name);

Her læser du alt hvad der bliver skrevet.

> break;
> case 'P': printf("Enter Bidder's Number: ");
> scanf("%d",&a);
> item[i].bidder=a-1;
> printf("Enter Price: ");
> scanf("%d",&item[i].price);
> break;
> case 'C': return;
> break;
> }
> } while(!(kbhit()));

Og her looper du, hvis der ikke er mere at læse, hvilket der ikke er da
du lige har læst det hele.

Prøv med: while(false); i stedet

--
Like a rat in a maze Anders Bo Rasmussen mailto:fuzz01@spamfilter.dk
The path before me lies Frimestervej 42 1.tv http://www.fuzz.dk
And the pattern never alters 2400 Kbh. NV
Until the rat dies.

Søg
Reklame
Statistik
Spørgsmål : 177558
Tips : 31968
Nyheder : 719565
Indlæg : 6408925
Brugere : 218888

Månedens bedste
Årets bedste
Sidste års bedste