fgets gets fputs puts

    技术2022-06-26  43

                                              fgets gets fputs puts

     

    fgets

    调用方式

    char *fgets( char *string, int n, FILE *stream )

    功能

    Get a string from a stream.

    返回值

    Each of these functions returns string. NULL is returned to indicate an error or an end-of-file condition. Use feof or ferror to determine whether an error occurred.

    注意

    The fgets function reads a string from the input stream argument and stores it in string. fgets reads characters from the current stream position to and including the first newline character, to the end of the stream, or until the number of characters read is equal to n – 1, whichever comes first. The result stored in string is appended with a null character. The newline character, if read, is included in the string.

    fgets is similar to the gets function; however, gets replaces the newline character with NULL.

     

    gets

    调用方式

    char *gets( char *buffer )

    功能

    Get a line from the stdin stream.

    返回值

    Each of these functions returns its argument if successful. A NULL pointer indicates an error or end-of-file condition. Use ferror or feof to determine which one has occurred.

    注意

    The gets function reads a line from the standard input stream stdin and stores it in buffer. The line consists of all characters up to and including the first newline character ('/n'). gets then replaces the newline character with a null character ('/0') before returning the line. In contrast, the fgets function retains the newline character.

     

    fputs

    调用方式

    int fputs( const char *string, FILE *stream )

    功能

    Write a string to a stream.

    返回值

    Each of these functions returns a nonnegative value if it is successful. On an error, fputs returns EOF.

    注意

    The function copies string to the output stream at the current position. The terminating null character the string is not copied.

     

    puts

    调用方式

    int puts( const char *string );

    功能

    Write a string to stdout.

    返回值

    Each of these returns a nonnegative value if successful. If puts fails it returns EOF.

    注意

    The puts function writes string to the standard output stream stdout, replacing the string’s terminating null character ('/0') with a newline character ('/n') in the output stream.


    最新回复(0)