首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >putc函数_C语言中的putc()函数与示例

putc函数_C语言中的putc()函数与示例

作者头像
用户7886150
修改2021-02-14 15:17:21
修改2021-02-14 15:17:21
1.2K0
举报
文章被收录于专栏:bit哲学院bit哲学院

参考链接: C++ putc()

putc函数

  C语言中的putc()函数 (putc() function in C) 

 The putc() function is defined in the <stdio.h> header file. 

  putc()函数在<stdio.h>头文件中定义。  

 Prototype: 

  原型:  

     int putc(const char ch, FILE *filename);

 Parameters: const char ch, FILE *filename 

  参数: const char ch,FILE *文件名  

 Return type: int 

  返回类型: int  

 Use of function: 

  使用功能:  

 In the file handling, through the putc() function, we write the character from the stdin to the input file stream and increments the file position pointer. The prototype of the function putc() is int putc(const char* string, FILE *filename); 

  在文件处理中,通过putc()函数 ,我们将来自stdin的字符写入输入文件流,并递增文件位置指针。 函数putc()的原型是int putc(const char * string,FILE * filename);  

 It returns an integer value which is conversion of an unsigned char. It also returns EOF, if an error occurs. Whenever there is a binary file check for error with the function ferror() 

  它返回一个整数值,该值是无符号字符的转换。 如果发生错误,它也会返回EOF 。 每当有二进制文件时,使用函数ferror()检查错误  

  C语言中的putc()示例 (putc() example in C) 

 #include <stdio.h>

#include <stdlib.h>

int main(){

    //Initialize the file pointer

    FILE *f;

    char ch;

    //Create the file for write operation

    f=fopen("includehelp.txt","w");

    printf("Enter five character\n");

    for(int i=0;i<5;i++){

        //take the characters from the users

        scanf("%c",&ch);

        //write back to the file

        putc(ch,f);

        //clear the stdin stream buffer

        fflush(stdin);

    }

    //close the file after write operation is over

    fclose(f);

    //open a file

    f=fopen("includehelp.txt","r");

    printf("Write operation is over and file is reday for read operation\n");

    printf("\n...............print the characters..............\n\n");

    while(!feof(f)){

        //takes the characters in the character array 

        ch=getc(f);

        //and print the characters

        printf("%c\n",ch);

    }

    fclose(f);

    return 0;

}

 Output 

  输出量  

  翻译自: https://www.includehelp.com/c-programs/putc-function-in-c-language-with-example.aspx

 putc函数

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档