Fgets () function and fputs () function

Source: Internet
Author: User

Fgets ()

Fgets ()        The function is a file operation related function     temporarily using this function can receive a string from the keyboard, save to the character array of        the original received string saved to the array method:            char str[50];        1) scanf ("%s", str); Disadvantage: Cannot receive space        2) gets (str);        Pros: Can receive                            a space//disadvantage: There will be an unsafe warning     fgets () is a safe string to receive the function                char ch[5];//If fgets is used, the maximum number of visible characters in the array is 4                    // will automatically store the last element of the array.     fgets () uses the format:                fgets (array name, array length, stdin);         For example:            char ch[5]            //fgets reads a string from the input buffer into a character array            //when the input string is longer than the length of the array, Fgets automatically            //turns the last element of the array into \ 0            //When the length of the input string is less than the length of the array, Fgets will also receive a carriage return            fgets (ch,sizeof (CH), stdin);            Remove the extra \ n            

Fputs ()

Fputs ();        is also a file operation related to the format of the function        :            fputs (array name, stdout);                For example:            fputs (ch,stdout);        Fputs is output that does not wrap        fputs and cannot be formatted

The biggest advantage of fgets () and fputs () is that they automatically intercept input strings, making it safe to store strings.

Fgets () function and fputs () function

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.