中文字幕一区二区人妻电影,亚洲av无码一区二区乱子伦as ,亚洲精品无码永久在线观看,亚洲成aⅴ人片久青草影院按摩,亚洲黑人巨大videos

C 庫(kù)函數(shù) - ungetc()

C 標(biāo)準(zhǔn)庫(kù) - <stdio.h> C 標(biāo)準(zhǔn)庫(kù) - <stdio.h>

描述

C 庫(kù)函數(shù) int ungetc(int char, FILE *stream) 把字符 char(一個(gè)無符號(hào)字符)推入到指定的流 stream 中,以便它是下一個(gè)被讀取到的字符。

聲明

下面是 ungetc() 函數(shù)的聲明。

int ungetc(int char, FILE *stream)

參數(shù)

  • char -- 這是要被推入的字符。該字符以其對(duì)應(yīng)的 int 值進(jìn)行傳遞。
  • stream -- 這是指向 FILE 對(duì)象的指針,該 FILE 對(duì)象標(biāo)識(shí)了輸入流。

返回值

如果成功,則返回被推入的字符,否則返回 EOF,且流 stream 保持不變。

實(shí)例

下面的實(shí)例演示了 ungetc() 函數(shù)的用法。

實(shí)例

#include <stdio.h>

int main ()
{
? ?FILE *fp;
? ?int c;
? ?char buffer [256];

? ?fp = fopen("file.txt", "r");
? ?if( fp == NULL )
? ?{
? ? ? perror("打開文件時(shí)發(fā)生錯(cuò)誤");
? ? ? return(-1);
? ?}
? ?while(!feof(fp))
? ?{
? ? ? c = getc (fp);
? ? ? /* 把 ! 替換為 + */
? ? ? if( c == '!' )
? ? ? {
? ? ? ? ?ungetc ('+', fp);
? ? ? }
? ? ? else
? ? ? {
? ? ? ? ?ungetc(c, fp);
? ? ? }
? ? ? fgets(buffer, 255, fp);
? ? ? fputs(buffer, stdout);
? ?}
? ?return(0);
}

假設(shè)我們有一個(gè)文本文件 file.txt,它的內(nèi)容如下。文件將作為實(shí)例中的輸入:

this is json
!c standard library
!library functions and macros

讓我們編譯并運(yùn)行上面的程序,這將產(chǎn)生以下結(jié)果:

this is json
+c standard library
+library functions and macros

C 標(biāo)準(zhǔn)庫(kù) - <stdio.h> C 標(biāo)準(zhǔn)庫(kù) - <stdio.h>

其他擴(kuò)展