c fputc 函数重写
C中的fputc()函数 (fputc() function in C)
Prototype:
原型:
int fputc(const char ch, FILE *filename);
Parameters:
参数:
const char ch, FILE *filename
Return type: int
返回类型: int
Use of function:
使用功能:
In the file handling, through the fputc() function we take the next character from the input stream buffer and put the characters in the file and increments the file pointer by one. The prototype of the function fputc() is: int fputc(const char ch, FILE *filename);
在文件处理中,通过fputc()函数,我们从输入流缓冲区中获取下一个字符,并将这些字符放入文件中,并将文件指针加1。 函数fputc()的原型是: int fputc(const char ch,FILE * filename);
Here it put the characters into the specified files and filename is the name of file stream.
此处将字符放入指定的文件中, 文件名是文件流的名称。
C中的fputc()示例 (fputc() 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
fputc(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("\n...............print the characters..............\n\n");
while(!feof(f)){
//takes the characters in the character array
ch=fgetc(f);
//and print the characters
printf("%c\n",ch);
}
fclose(f);
return 0;
}
Output
输出量
翻译自: https://www.includehelp.com/c-programs/fputc-function-in-c-language-with-example.aspx
c fputc 函数重写