Puts () and gets () Functions

Source: Internet
Author: User

Http://blog.csdn.net/pipisorry/article/details/39406501

Non-formatted input/output functions

These functions can be replaced by the standard formatted input and output functions described above. However, these functions have less code after compilation and consume less memory, which increases the speed and is convenient to use.

Puts () and gets () Functions

1. Puts () function

The puts () function is used to write strings and line feed to the standard output device (screen,

Call format: puts (s );

S is a string variable (string array name or string pointer ).

The puts () function works the same way as printf ("% s \ n", S.

Main () {char s [20], * F; strcpy (S, "Hello world! ");/* String array variable assignment */F =" thank you ";/* string pointer variable assignment */puts (s); puts (f );}


Note:

(1). The puts () function can only output strings and cannot output numeric values or perform format conversion.

(2). Strings can be directly written to the puts () function. For example:

Puts ("Hello, Turbo c2.0 ");

 

2. Gets () function

The gets () function is used to read a string from the standard input device (keyboard) until the carriage return ends, but the carriage return does not belong to this string.

Call format: gets (s );

S is a string variable (string array name or string pointer ).

The gets (s) function is similar to scanf ("% s", & S), but not exactly the same. Use scanf ("% s", & S) A problem occurs when the function inputs a string, that is, if a space is entered, the input string ends,

The character after the space is processed as the next input, but the gets () function will receive the entire input string until the carriage return.

Main () {char s [20], * F; printf ("input something \ n"); gets (s ); /* wait until the input string ends by pressing enter */puts (s);/* output the input string */puts ("input something \ n"); gets (f ); puts (f );}


From:

Http://blog.csdn.net/pipisorry/article/details/39406501

Ref: http://www.cnblogs.com/wanhl/archive/2012/08/16/2641651.htmlcin、cin.get (), Cin. Getline (), Getline (), gets () Usage


Puts () and gets () Functions

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.