文件的内容是“我爱计算机”。使用fgets()读取文件,结果存储在数组buff中。 buff包含什么? [英] A contents of a file are “I love computerrn”. The file is read using fgets() and the result is stored in array buff. What does buff contain?

查看:86
本文介绍了文件的内容是“我爱计算机”。使用fgets()读取文件,结果存储在数组buff中。 buff包含什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

怎么办这个问题?我不知道答案请帮帮我。



我尝试了什么: < br $>


i不知道答案让我知道。怎么做这个问题?我不知道答案请帮帮我。

how to do this question?I don't know the answer please help me out.

What I have tried:

i don't know the answer let me know.how to do this question?I don't know the answer please help me out.

推荐答案

问题可能不是:文件内容更可能是我喜欢计算机\\\\ n这是非常不同的。



但这是你的作业:所以这是你的任务。

首先查看 fgets的定义 fgets - C ++参考 [ ^ ]很明显,你得到的将取决于你传递给它的参数 - 计数是重要的。如果计数为3,您将在缓冲区中存储四个字符:'I','','l'和'\0' - 最后一个是用于标记字符串结尾的空终止符。其他值将为您提供其他结果...



尝试:查看问题,设置文件,然后编写代码来执行此操作,并使用调试器,以确切了解发生了什么。这并不复杂!
Chances are that the question is not that: the file content is more likely to be "I love computer\r\n" which is very different.

But this is your homework: so it's your task.
Start by looking at the definition of fgets: fgets - C++ Reference[^] and it's obvious that what you get will depend on the parameters you pass to it - the count is significant. If the count is 3, you will get four characters stored in the buffer: 'I', ' ', 'l', and '\0' - the last being a null terminator to mark the end of the string. Other values will give you other results...

Try it: look at the question, set up the file, and write the code to do it, and use the debugger to find out exactly what happens. This isn't complicated!


这篇关于文件的内容是“我爱计算机”。使用fgets()读取文件,结果存储在数组buff中。 buff包含什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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