Monday, 15 June 2015

c - What is sent to the program when the user presses enter in the console? -


EDIT: DanielFischer indicates the problem with the code given below, if any are curious.

If a user enters a formatted string and the press is actually sent to the program which is reading it?

  enter name & gt; John Smith   

Does it only send an empty end string or does a marked character say that he also hits the hit?

EDIT: I thought what Mike would say would be true. But then why does not this snippet of code work?

  printf ("enter command";); Memeset (buff, 0, buffs); Do {temp = getchar (); If {temp! = '\ N') strcat (buf, & temp); } While (temp! = '\ N'); Dome (buff, "\ 0"); What is sent to the terminal is 10 characters:  
   

[ja] [o] [h] [n] [] [s] [m] [t] [h] [\ n]

How the program handles it, depends on the function being used to read the input. The last character is there ( '\ n' ) indicates that we press "enter".

A redundant string is a concept for a program (i.e. string essential functions to make it work properly), you do not have one tap terminator coming from stdin in your example will see.

This is the reason why you need to understand how works that accept user data, if it takes a new look, you may need to snatch it. If it does not automatically attach a redundant terminator, then you probably have to add one etc.

No comments:

Post a Comment