日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2025/3/11 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 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函數

總結

以上是生活随笔為你收集整理的c语言getchar函数_C语言中带有示例的getchar()函数的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。