c语言getchar函数_C语言中带有示例的getchar()函数

c语言getchar函数

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

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

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

Prototype:

原型:

    int getchar(void);

Parameters: FILE *filename(for file handling), otherwise it will be void.

参数: FILE * filename(用于文件处理) ,否则为空。

Return type: int

返回类型: int

Use of function:

使用功能:

In the file handling, through the getchar() function we take the character from the input stream stdin. The prototype of the function getchar() is int getchar(void);

在文件处理中,通过getchar()函数,我们从输入流stdin中获取字符。 函数getchar()原型是int getchar(void);。

The character which is read is an unsigned char which is converted to an integer value. In the case of file handling, it returns EOF when end-of-file is encountered. If there is an error then it also returns EOF.

读取的字符是无符号字符 ,该字符将转换为整数值。 在文件处理的情况下,遇到文件结尾时它将返回EOF 。 如果有错误,则它还会返回EOF 。

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

#include <stdio.h>
#include <stdlib.h>

int main(){
	//Initialize the character array
	char str[100];
	int i=0,j=0;
	
	printf("Enter the string into the file\n");
	//takes all the characters until enter is pressed
	while((str[i]=getchar())!='\n'){
		//increment the index of the character array
		i++;
	}
	
	//after taking all the character add null pointer 
	//at the end of the string
	str[i]='\0';
	printf("\nThe file content is - ");
	//loop is break when null pointer is encountered
	while(str[j]!='\0'){
		//print the characters
		putchar(str[j]);
		j++;
	}
	
	return 0;
}

Output

输出量

getchar() example in C language

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

c语言getchar函数

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值