编写一个接受用户输入并应该找到输入文件的 C 程序?
我应该使用 for 循环来使用输入 - 不知道为什么要使用 for 循环?我的意思是这个程序所做的就是继续要求用户输入文件名,开始查找添加以及要读取的字节数。
例如,输入应如下所示:
%myprog 输入文件名:数据文件 开始查找:0 要读取的字节数:65
此程序中的块大小为 20,因此输出为:
“m/n/files/program/test/datafile” block 0 read - 20 bytes 01234567890123456789 “m/n/files/program/test/datafile”块 1 读取 - 20 字节 01234567890123456789 “m/n/files/program/test/datafile”块 3 读取 - 20 字节 01234567890123456789 “m/n/files/program/test/datafile”块 0 读取 - 5 个字节 01234
所以我不确定为什么/如何使用 for 循环来请求用户输入。我们所做的就是继续要求用户输入不同的文件并查找范围。作业没有说明在哪里停止询问。
I am supposed to use a for loop for use input
-Not sure why a for loop? I mean all this program does is keep on asking the user to input a filename, a starting seek adds and the # of bytes to read off.
For example, the input should look like:
%myprog
Enter filename:datafile
Start seek:0
Bytes to read:65
My block size in this program is 20, so the output would be:
"m/n/files/program/test/datafile" block 0 read - 20 bytes
01234567890123456789
"m/n/files/program/test/datafile" block 1 read - 20 bytes
01234567890123456789
"m/n/files/program/test/datafile" block 3 read - 20 bytes
01234567890123456789
"m/n/files/program/test/datafile" block 0 read - 5 bytes
01234
So I am not sure why/how I would use a for loop to ask for user input. All we are doing is keep on asking the user to enter different files and seek ranges. The assignment does not say where to stop asking.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
for
循环是 C 中的通用循环结构。以下循环是等效的。
FOR LOOP
WHILE LOOP
假设您知道这一点,您可以编写以下相当迟钝的代码,尽管它可能会让人皱眉:
The
for
loop is the universal looping construct in C.The following loops are equivalent.
FOR LOOP
WHILE LOOP
Assuming you know this, you could write the following rather obtuse code, although it might be frowned upon:
写一些类似的东西:
Write something like: