腾讯总部客服电话:【求助】标准的C程序--输出文件的末尾行(对最佳结果追加30分)

来源:百度文库 编辑:查人人中国名人网 时间:2024/05/03 10:32:22
请朋友帮帮忙 用标准C写下 谢谢!谢谢!

【问题描述】
命令 tail用来打印文件中最后n行。
命令格式为:tail [-n] filename,其中:
-n :n表示需要打印的行数,省略时n的值为10。
filename :给定文件名。
如,命令tail -20 example.txt 表示打印文件example.txt的最后20行。用C语言实现该程序,该程序应具有一定的错误处理能力,如能处理非法命令参数和非法文件名。(提示:使用命令行参数)
【输入形式】
tail [-n] filename,其中:-n :n表示需要打印的行数,省略时n的值为10。
filename :给定文件名。
【输出形式】

打印文件filename的最后n行
【输入样例】
命令:tail -2 tail.in
tail.in文件内容为:
Alcatel provides end-to-end solutions.
It enables enterprises to deliver content to any type of user.
lcatel operates in 130 countries.
Alcatel focus on optimizing their service offerings and revenue streams.

【输出样例】
屏幕将显示:
lcatel operates in 130 countries.
Alcatel focus on optimizing their service offerings and revenue streams.

【样例说明】
使用tail -2 tail.in输出文件tail.in的最后两行。