TIP: Click on subject to list as thread! ANSI
echo: cis.languages
to: SCOTT HOWELL 70270,641 (X)
from: Scott t. Griepentrog 72427,335
date: 1990-06-26 19:44:59
subject: #4656-thanks to all

#: 4665 S3/Languages
    26-Jun-90  19:44:59
Sb: #4656-thanks to all
Fm: Scott t. Griepentrog 72427,335
To: SCOTT HOWELL 70270,641 (X)

Whoa! Wrongo!

read(0,&ch,1);   - puts char in (char) ch

BUT!!!

strcmp("q",ch);

is TOTALLY wrong.  1) assuming ch is declared 'char ch;' you have only one byte
allocated.  Strings are multiple bytes... AND strcmp expects a pointer to
string.  A char is not going to work!

strcmp("q",&ch);

would be closer, but still wrong.  You must have a zero terminator to both
strings, and you have no idea what follows the char ch in memory!

There are two alternatives:

char ch[2]; ch[1]=0; read(0,ch,1); strcmp("q",ch);

OR

char ch; read(0,&ch,1); if (ch=='q') ...;

Of course the latter makes more sense.

Want some additional help on C?  You can call me at (317)241-6401, or mail me
here or any StG-net node at sysop@root.

StG

SOURCE: compuserve via textfiles.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.