[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: help with C program



Meidan Zemer wrote:
> 
> For some reason "getchat()" accept Null string and do'nt  prompt for
> the user.
> I run  kernel 2.2.3 on pentium 120 with 32MG
> I am sure it is somting simple but i just can'nt see it!!
> Does anybody have any idea about it?

Well, first of all...why not change settings in you mail composer so
that
messages will be composed in plain text format and not in HTML? :))))

Now, as for your problem, it seemes like getchar() receives the
character
with ASCII code 0A which is LineFeed symbol. This is because scanf() 
reads characters from system input UNTIL CR/LF or LF and then appends 
null-character. So LF remains in the input stream and getchar() reads
it.

For example, if you type 

hello<Enter>

scanf() will return 

hello\0

and LF character is still in the stream. Then you call getchar()
and it returns LF. So instead of 'num=getchar();' you can write
something
like 'while ((num=getchar()) <= 32); //do nothing' if you want
getchar() to wait for printable character.

-- 
-------------------------------------------------------------
|         Eugene L. Berman           |                      |
|            --<<-+-<<@              |                      |
| E-Mail:   eugene@mannanetwork.com  |   NIHIL HABENTES,    |
| Phone #:  ++972-3-5538210          |  OMNIA POSSIDENTES.  |
| Mobile #: 054-809439               |                      |
| http://www.mannanetwork.com        |                      |
-------------------------------------------------------------

=================================================================
To unsubscribe, send mail to linux-il-request@linux.org.il with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail linux-il-request@linux.org.il