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

c语言fgetc函数

C中的fgetc()函数 (fgetc() function in C)

Prototype:

原型:

    int fgetc(FILE *filename);

Parameters:

参数:

    FILE *filename

Return type: int

返回类型: int

Use of function:

使用功能:

In the file handling, through the fgetc() function we take the next character from the input stream and increments the file pointer by one. The prototype of the function fgetc() is: int fgetc(FILE* filename);

在文件处理中,通过fgetc()函数,我们从输入流中获取下一个字符,并将文件指针加1。 函数fgetc()的原型是: int fgetc(FILE * filename);

It returns an integer value which is conversion of an unsigned char. It also returns EOF which also in turns an integer value.

它返回一个整数值,该值是无符号char的转换。 它还返回EOF ,而EOF也是一个整数值。

C中的fgetc()示例 (fgetc() 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("File content is--\n");
	printf("\n...............print the strings..............\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

输出量

fgetc example in c

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

c语言fgetc函数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值