Modify sh.c so that all commands entered by the user are appended to a file called commands.txt. The commands should be logged into the file before they are If txt does not exist, your program is responsible for creating it. Create a program called frequency.c. This program will read from commands.txt and display the number of times each command occurred. You are not allowed to request more memory than necessary during the calculation of the frequency. You need to implement and apply the following two utility functions:
Modify sh.c so that all commands entered by the user are appended to a file called commands.txt.
- The commands should be logged into the file before they are
- If txt does not exist, your program is responsible for creating it.
Create a program called frequency.c. This program will read from commands.txt and display the number of times each command occurred.
You are not allowed to request more memory than necessary during the calculation of the frequency.
You need to implement and apply the following two utility functions:
- int num_elements(char* str);
This function counts the number of characters in string str.
- void append(char** str, char c);
This function appends char c to string str. It might need to resize str.
The output should be in the form <command>:<occurrence> for each unique command in commands.txt.
You also need to provide a readme file (in PDF format) to (i) answer the questions in Part A; (ii) explain the major points of your program.
Sample run:
$ frequency
ls: 3
cat commands.txt: 1
echo hello: 2
echo goodbye: 1
frequency: 2
$
Step by step
Solved in 2 steps