#: 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
|