Login Register






Need help in C ( Detect char) filter_list
Author
Message
Need help in C ( Detect char) #1
-------------------------
(This post was last modified: 06-05-2019, 06:25 PM by chemicalrage.)

Reply

RE: Need help in C ( Detect char) #2
Read a char instead of int:

Code:
char ch; //... scanf(" %c", &ch); if(ch == '1') { //...
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.

[Image: 2YpkRjy.png]

Reply

RE: Need help in C ( Detect char) #3
-------------------------
(This post was last modified: 06-05-2019, 06:25 PM by chemicalrage.)

Reply

RE: Need help in C ( Detect char) #4
I don't understand what the problem with the char is, but you can read the return code of scanf instead. If it is greater than 0, reading was successful.

Code:
int rc; rc = scanf("%d", &ch); if(rc > 0) { //success }

Look into the c reference for scanf to get more information: http://www.cplusplus.com/reference/cstdio/scanf/

Quote:On success, the function returns the number of items of the argument list successfully filled. This count can match the expected number of items or be less (even zero) due to a matching failure, a reading error, or the reach of the end-of-file.

If a reading error happens or the end-of-file is reached while reading, the proper indicator is set (feof or ferror). And, if either happens before any data could be successfully read, EOF is returned.

If an encoding error happens interpreting wide characters, the function sets errno to EILSEQ.
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.

[Image: 2YpkRjy.png]

Reply