zoukankan      html  css  js  c++  java
  • fgets

    char * fgets ( char * str, int num, FILE * stream );

    Get string from stream
    Reads characters from stream and stores them as a C string into str until (num-1) characters have been read or either a newline or a the End-of-File is reached, whichever comes first.
    A newline character makes fgets stop reading, but it is considered a valid character and therefore it is included in the string copied to str.
    A null character is automatically appended in str after the characters read to signal the end of the C string.

    Parameters

    str
        Pointer to an array of chars where the string read is stored.
    num
        Maximum number of characters to be read (including the final null-character). Usually, the length of the array passed as str is used.
    stream
        Pointer to a FILE object that identifies the stream where characters are read from.
        To read from the standard input, stdin can be used for this parameter.

    /* fgets example */
    #include <stdio.h>

    int main()
    {
       FILE * pFile;
       char mystring [100];

       pFile = fopen ("myfile.txt" , "r");
       if (pFile == NULL) perror ("Error opening file");
       else {
         if ( fgets (mystring , 100 , pFile) != NULL )
           puts (mystring);
         fclose (pFile);
       }
       return 0;
    }

  • 相关阅读:
    CCF 201712-4
    图论_最短路径
    图论_查并集
    let和const
    Promise
    实现表单label两端对齐
    始终让footer在底部
    react——使用this.setState({ })修改state状态值
    react——css样式
    react脚手架
  • 原文地址:https://www.cnblogs.com/greencolor/p/2219562.html
Copyright © 2011-2022 走看看