Can someone help me with this Unix system command code? Writing in C Description
ID: 3692597 • Letter: C
Question
Can someone help me with this Unix system command code? Writing in C
Description:
Read the man pages for the wc system command. Then, write your own version of wc that supports the -c, -m, and -l options.
Your version only has to support reading from a single file.
Synopsis of your version:
wc FILE [OPTION]
Sample Usages:
./wc file.txt c displays the number of bytes in file.txt
./wc file.txt l displays the number of lines in file.txt
./wc file.txt lc displays the number of bytes and the number of lines in file.txt
./wc file.txt cl displays the number of bytes and the number of lines in file.txt
./wc displays synopsis
./wc file.txt display number of bytes and number of lines
./wc dog.txt displays an error message if dog.txt fails to open
You must use Unix system calls wherever possible: open, close, read, write, creat, etc.
Hints:
Consider writing an algorithm for the program first, and then implement the algorithm one step at a time.
You can test for the null terminator with an expression such as: ( x != '' )
The source text file remains unmodified no matter what.
You may find some functions in ctype.h useful.
Explanation / Answer
Ans;
1) displays the contents from file.txt to the screen, with all the a's changed to z's.
$nano file.txt
$vi file.txt
echo "this is a sample file."
$tr 'a' 'z' <file.txt
this is z szmple file
2)
Copying and moving files
When copying files from one directory to another you need to know for certain which directory is the current working directory. If you are not sure, use the pwd command.
Make a copy in the current directory
$touch output.txt
$cp file.txt output.txt
3)
In computer programming, a usage message or help message refers to a brief message displayed by a program that utilizes a command-line interface for execution. This message usually consists of the correct command line usage for the program and includes a list of the correct command-line arguments or options acceptable to said program.
Usage messages are utilized as a quick way for a program to inform the user of proper command syntax, and should not be substituted for detailed documentation, such as aman page.
ex:
Explanation of the code:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.