putc函数_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 pointerFILE *f;char ch;//Create the file for write operationf=fopen("includehelp.txt","w");printf("Enter five character\n");for(int i=0;i<5;i++){//take the characters from the usersscanf("%c",&ch);//write back to the fileputc(ch,f);//clear the stdin stream bufferfflush(stdin);}//close the file after write operation is overfclose(f);//open a filef=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 charactersprintf("%c\n",ch);}fclose(f);return 0; }Output
輸出量
翻譯自: https://www.includehelp.com/c-programs/putc-function-in-c-language-with-example.aspx
putc函數
總結
以上是生活随笔為你收集整理的putc函数_C语言中的putc()函数与示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 为什么阿里全面推动 K8S 落地,咬紧牙
- 下一篇: 各大厂面试高频的面试题新鲜出炉,你能答上