zoukankan      html  css  js  c++  java
  • fgets和fputs函数

    1 函数输入

    下面两个函数提供每次输入一行的功能。

    #include <stdio.h>
    char *fgets( char *restrict buf, int n, FILE *restrict fp );
    char *gets( char *buf );
              两个函数返回值:若成功则返回buf,若已到达文件结尾或出错则返回NULL

    这两个函数都指定了缓冲区的地址,读入的行将送入其中。gets从标准输入读,而fgets则从指定的流读。

    2  函数输出

    提供每次输出一行的功能。

    #include <stdio.h>
    int fputs( const char *restrict str, FILE *restrict fp );
    int puts( const char *str );
                两个函数返回值:若成功则返回非负值,若出错则返回EOF

     

    例子:

    #include <stdio.h>
    #define n 9
    char buf[n];
    int main()
    {
      int i;
      if (fgets(buf,n,stdin)!=NULL)
        printf("fgets success ");
      else printf("fgets error ");
      i=fputs(buf,stdout);
      if(i>0) printf(" fputs success ");
      else printf(" fputs error ");

      return 0;
    }

  • 相关阅读:
    Redis数据类型
    Linux配置Redis
    Linux配置ActiveMQ
    Linux配置Docker
    3、Spring Boot日志
    2、Spring Boot配置
    1. Spring Boot入门
    Linux(centos6.8)配置Redis
    okhttp禁止重定向
    123
  • 原文地址:https://www.cnblogs.com/hezhangyear/p/4038907.html
Copyright © 2011-2022 走看看