CSc 3320
Programming project #1
DUE DATE: September 11, 2002
Objectives
- Practice using the Unix OS and vi or emacs or pico editor.
- Practice implementing a program design in C.
- Learn how to call a utility function in C with the “system” command.
- Practice the concepts of pipe and redirection.
- To get familiar with the programming environment.
Project
In this project, you are going to write a C program to read a string and to call utility functions with the “system” command. Your program is essentially the same command as you type in your input, but with sorted outputs. For example, if your input to the program is “ls”, the output will be the same as that from “ls | sort”. We assume that pipes were not available in our environment and we try to implement pipes using redirection. Thus, pipes are not allowed in your code. Please test your program thoroughly using different inputs.
Here are the details of your program description:
- Your program should first print the date and time of day on the standard output using the function system(char, *) and then print out the current directory.
- It then reads a command from the user as a string. For our purposes, implement a string as an array of chars. Use "strcpy", "strcat", and "strcmp" commands as needed.
- Append the output redirection character to the string, followed by a temporary file name “temp1”. Execute the command with the "system" command. Report the returned status.
- Form a string “sort < temp1 > temp2” and execute the command in the string with the “system” command.
- Read the file temp2 created in step 4 and echo its contents to the screen.
- Remove both temporary files temp1 and temp2.
- Name your source file 'assign1.c' and store it in your home directory.
- Be sure to include the following information as comments in the
header of your source file:
/*
assign1.c
Author: Your Name
Account: your account number
CSc 3320
Program #1
Due date: September 11, 2002
Description:
Give a brief description of what your program does.
Input:
State what the program inputs are.
Output:
State what the program outputs are.
*/
- You are aware certain types of assistance are inappropriate in this
class. Read the collaboration policy given to you at the beginning of
the semester, if you have any questions. - Follow program standards as presented in class and in your book.
Pay special attention to comments, identifier style, and consistent
3-space indentation. - Turn In Hard Copies of:
your source code; and the output from three different executions in which you test the correctness of your program (using a script).
Use script assign1.log to record all things you type and the responses from the system. "assign1.log” is just the name of the file it creates. After finishing the recording, type CTRL-D to exit from your script session.