主题:求助Unix下的C
求助写一个unix下的c 语言程序,是关于文件处理类型的,要求创建2个命令让文件执行。
不求源代码,只求告知从何处着手这个程序即可。
Command name: fold
Purpose: To fold long lines for output to the console window
Synopsis: fold [-s] [-w width] file ...
Description:
The fold utility is a filter which folds the contents of the specified files, breaking the lines to have a maximum of 80 columns (or a different maximum if the -w option is used).
The options are as follows:
-s Fold line after the last space character within the first width column positions. If there is no such space character, fold anyway. This is similar to "word wrap".
-w width Specify a line width to use instead of the default 80 columns.
Assumptions:
* There will always be one or more filenames on the command line.
o All filenames are guaranteed to be after all options.
* Filenames never start with '-'.
* The files are guaranteed to be text files if they exist.
o However, the files are not guaranteed to exist or be accessible (see Errors section).
* The maximum length of a line found within the file is 65535 characters.
* The files will not contain backspace characters or TAB characters.
Comments:
* The options can be in any order and might or might not be present.
* Each option must have its own "-" preceding it (e.g. it is not permissible to have -sw).
* There might or might not be a space between the -w and the specified width.
* A '\n' character is actually a carriage return character (ASCII value 0x0d) followed by a line feed character (ASCII value 0x0a).
* Files do not necessarily end with a '\n'.
o The reason for this is that some editing programs put the '\n' at the end and some do not
* If width is anything other than a positive integer less than 65535, display a usage error message.
Errors:
* Displays a "File not openable" error message and terminates without any other further output if any of the files cannot be opened.
o If this happens on a second or subsequent file, it is OK to process the previous files that can be opened.
* Displays a "Usage: fold [-s] [-w width] file ..." error message and terminates if the command line options are incorrect.
o Your error message must look exactly as stated above.
* Displays an appropriate error message and terminates without any other further output if there is a error with reading or closing any of the files.
Exit Status:
0 successful
1 can't open file
2 command line options incorrect
3 any other fatal errors
不求源代码,只求告知从何处着手这个程序即可。
Command name: fold
Purpose: To fold long lines for output to the console window
Synopsis: fold [-s] [-w width] file ...
Description:
The fold utility is a filter which folds the contents of the specified files, breaking the lines to have a maximum of 80 columns (or a different maximum if the -w option is used).
The options are as follows:
-s Fold line after the last space character within the first width column positions. If there is no such space character, fold anyway. This is similar to "word wrap".
-w width Specify a line width to use instead of the default 80 columns.
Assumptions:
* There will always be one or more filenames on the command line.
o All filenames are guaranteed to be after all options.
* Filenames never start with '-'.
* The files are guaranteed to be text files if they exist.
o However, the files are not guaranteed to exist or be accessible (see Errors section).
* The maximum length of a line found within the file is 65535 characters.
* The files will not contain backspace characters or TAB characters.
Comments:
* The options can be in any order and might or might not be present.
* Each option must have its own "-" preceding it (e.g. it is not permissible to have -sw).
* There might or might not be a space between the -w and the specified width.
* A '\n' character is actually a carriage return character (ASCII value 0x0d) followed by a line feed character (ASCII value 0x0a).
* Files do not necessarily end with a '\n'.
o The reason for this is that some editing programs put the '\n' at the end and some do not
* If width is anything other than a positive integer less than 65535, display a usage error message.
Errors:
* Displays a "File not openable" error message and terminates without any other further output if any of the files cannot be opened.
o If this happens on a second or subsequent file, it is OK to process the previous files that can be opened.
* Displays a "Usage: fold [-s] [-w width] file ..." error message and terminates if the command line options are incorrect.
o Your error message must look exactly as stated above.
* Displays an appropriate error message and terminates without any other further output if there is a error with reading or closing any of the files.
Exit Status:
0 successful
1 can't open file
2 command line options incorrect
3 any other fatal errors