c语言getchar函数_C语言中带有示例的getchar()函数
c語言getchar函數(shù)
C語言中的getchar()函數(shù) (getchar() function in C)
The getchar() function is defined in the <stdio.h> header file.
getchar()函數(shù)在<stdio.h>頭文件中定義。
Prototype:
原型:
int getchar(void);Parameters: FILE *filename(for file handling), otherwise it will be void.
參數(shù): 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()函數(shù),我們從輸入流stdin中獲取字符。 函數(shù)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.
讀取的字符是無符號字符 ,該字符將轉(zhuǎn)換為整數(shù)值。 在文件處理的情況下,遇到文件結(jié)尾時它將返回EOF 。 如果有錯誤,則它還會返回EOF 。
C語言中的getchar()示例 (getchar() example in C)
#include <stdio.h> #include <stdlib.h>int main(){//Initialize the character arraychar str[100];int i=0,j=0;printf("Enter the string into the file\n");//takes all the characters until enter is pressedwhile((str[i]=getchar())!='\n'){//increment the index of the character arrayi++;}//after taking all the character add null pointer //at the end of the stringstr[i]='\0';printf("\nThe file content is - ");//loop is break when null pointer is encounteredwhile(str[j]!='\0'){//print the charactersputchar(str[j]);j++;}return 0; }Output
輸出量
翻譯自: https://www.includehelp.com/c-programs/getchar-function-in-c-language-with-example.aspx
c語言getchar函數(shù)
總結(jié)
以上是生活随笔為你收集整理的c语言getchar函数_C语言中带有示例的getchar()函数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何在Java中检查字符串是否为数字?
- 下一篇: 无法从ftp服务器上复制文件格式,ftp