C语言 - 基础 - fputs()

  原型:int fputs(const char *str, FILE *stream)

  参数解释:
      const char *str : const限制函数内部修改指针指向的数据(在函数形参使用const)
                 char *str 字符数组
      FILE *stream :stream 指向FILE对象的指针
      
      返回值:正确-int非零,错误-EOF(0)

  实例:
    (1)利用fputs()向控制台输出信息
    
        fputs("Hello world", stdout); stdout - 标准输出流
    
    (2)写入文件
    
      char* filePath = "D:\\student.txt";
        FILE * file = NULL;
        errno_t err;
        if ((err = fopen_s(&file, filePath, "w+")) != 0){
            printf_s("文件打开失败。");
            exit(0);
        }
        else{
           fputs("Hello world", file);
        }
        fclose(file);


   相似:fputc(),fgets():fgets(buffer, SIZE, stdin) != NULL

 

posted @ 2019-03-24 14:10  丨Kouch  阅读(344)  评论(0编辑  收藏  举报