tft每日頭條

 > 生活

 > c語言基礎函數表

c語言基礎函數表

生活 更新时间:2024-07-22 03:10:04

c語言基礎函數表?原函數:int ungetc(int char, FILE *stream),我來為大家講解一下關于c語言基礎函數表?跟着小編一起來看一看吧!

c語言基礎函數表(C語言庫函數之ungetc詳解)1

c語言基礎函數表

原函數:

int ungetc(int char, FILE *stream)

函數說明: int ungetc(int char, FILE *stream) 将字符的字符(unsigned char類型)到指定的流,用于下一個讀操作。

參數:

  • char -- 是被放回到字符。這是通過作為整型轉換。
  • stream -- 是一個文件對象的指針,識别輸入流。

返回值:

如果成功,則返回字符推回,否則,返回EOF并流保持不變。

如何使用ungetc() 函數:

#include <stdio.h>

int main () {

FILE *fp;

int c;

char buffer [256];

fp = fopen("file1.txt", "r");

if( fp == NULL ) {

perror("Error in opening file \n");

return -1;

}

while(!feof(fp)) {

c = getc (fp); /* replace ! with */

if( c == '!' ) {

ungetc (' ', fp);

} else {

ungetc(c, fp);

}

fgets(buffer, 255, fp);

fputs(buffer, stdout);

}

return 0;

}

假設有一個文本文件file1.txt,其中包含以下數據。

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

編譯和運行上面的程序,産生如下結果:

this is myfoal

c standard library

library functions and macros

library functions and macros

,

更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!

查看全部

相关生活资讯推荐

热门生活资讯推荐

网友关注

Copyright 2023-2024 - www.tftnews.com All Rights Reserved