是什么putc将和与ungetc之间的区别? [英] What is the difference between putc and ungetc?

查看:252
本文介绍了是什么putc将和与ungetc之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

INT与ungetc(INT C,FILE * FP)推字符c回到FP,并返回无论是C或 EOF 的错误。

int ungetc(int c, FILE *fp) pushes the character c back into fp, and returns either c, or EOF for an error.

在这里为int putc将(INT C,FILE * FP)写入字符c到文件FP并返回写入字符,或 EOF 的错误。

where as int putc(int c, FILE *fp) writes the character c into the file fp and returns the character written, or EOF for an error.

//这些都是从K&安培的陈述; R。我发现自己困惑,因为 putc将()可以在 GETC 使用,并可以为工作与ungetc 。因此,whats在具体定义使用与ungetc()

//These are the statements from K&R. I find myself confused, because putc() can be used after getc and can work as ungetc. So whats the use in specifically defining ungetc().

推荐答案

putc将写的东西输出,所以才出现在屏幕上或文件中,你'已经重定向输出。

putc writes something to output, so it appears on the screen or in the file to which you've redirected output.

与ungetc 把东西放回的输入的缓冲区,所以下次你打电话时间 GETC (或龟etc 等),这就是你会得到什么。

ungetc put something back into the input buffer, so the next time you call getc (or fgetc, etc.) that's what you'll get.

您通常使用 putc将写输出。您通常使用,当你读的输入,你知道你已经达到的事情结束的唯一办法是,当你读到不能部分字符与ungetc 目前东西。比如,你正在阅读和转换一个整数,你继续下去,直到你读其他的东西比一个数字 - 那么你与ungetc 非数字字符进行处理作为下一个一些从流的到来。

You normally use putc to write output. You normally use ungetc when you're reading input, and the only way you know you've reached the end of something is when you read a character that can't be part of the current "something". E.g., you're reading and converting an integer, you continue until you read something other than a digit -- then you ungetc that non-digit character to be processed as the next something coming from the stream.

这篇关于是什么putc将和与ungetc之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆