while ((c = GetChar ())! = EOF) (keyboard input problem)

Source: Internet
Author: User

Problem Description:

Sample input: O S

Sample output: I A

Code implementation:

1#include <stdio.h>2 3 Char*s ="' 1234567890-=qwertyuiop[]\\asdfghjkl; ' Zxcvbnm,./'";4 intMain ()5 {6     intc,i;7      while((c = GetChar ())! =EOF)8     {9          for(i =1; S[i] && s[i]!=c;i++);Ten         if(S[i]) One         { APutchar (s[i-1]); -         } -         Else the         { - Putchar (c); -         } -     } +     return 0; -}

Personal thoughts:

The input buffer is a row buffer. When you enter a string of characters from the keyboard and press ENTER, the characters inode are first sent to the input buffer for storage. Note that the only character that is returned is the first character of the input, which is the number one in the buffer. Then call GetChar () again, which will determine if there is data in the buffer, read the first character of the buffer if there is data, and then return. This goes down until the buffer is empty and waits for the input data. That's why input ABC will print ABC.

while ((c = GetChar ())! = EOF) (keyboard input problem)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.