哈尔滨极地馆订票官网:UNIX下计算文件的长度实现的原理和方法

来源:百度文库 编辑:神马品牌网 时间:2024/05/02 08:01:32
实用文件长度计算命令实现
1 目的
掌握UNIX应用程序设计的基本原理和方法。
2 内容
创建程序mycount,能判断出一个文件中的数据的具体大小,其中文件名作为mycount程序的参数。
3 要求
1)命令功能要能够完成实际应用的要求,实现对各种文件长度的计算功能。
2)分别以shell和c程序编写这个程序,比较哪一种效率更高,哪一种运行速率更快,写出你运用操作系统知识得到的理由,并得出结论。

我需要原理和方法,以及(2)中的所有内容

这个问题较简单。

UNIX中的 wc 就是干这个工作的

NAME
wc - print the number of bytes, words, and lines in files

SYNOPSIS
wc [OPTION]... [FILE]...

DESCRIPTION
Print line, word, and byte counts for each FILE, and a
total line if more than one FILE is specified. With no
FILE, or when FILE is -, read standard input.

-c, --bytes, --chars
print the byte counts

-l, --lines
print the newline counts

-L, --max-line-length
print the length of the longest line

-w, --words
print the word counts
--------------------------------------------
C 程序也好写,一个byte一个byte地读入,
统计 byte, new_line 的个数就可以了。