Description
Task #1: Write a C main function that takes one command-line argument, the name of an input
file. The input file contains exactly one integer spread out over a single line of up to 80
characters. For example, the integer 3579 is embedded in the line az3mqrm5t?7!z*&gqmzt9v.
Your program uses system calls to do the following:
a. open and read the input file, accumulating the discovered digit characters into a
character array (string).
b. Convert the string to an integer./taskdr (do not use atoi function).
c. Add 10 to the integer
d. convert the sum back to a string (using function convIntToStr)
e. make a system call to write the string to standard output.
/* Returns a non-zero value if character c is a digit, zero otherwise. */
int isdigit(int c)
You need include five headers <unistd.h>, <fcntl.h>, <ctype.h>, <stdio.h> and <string.h> for
read write open system calls and sprint return strlen library functions.
/************************************************
Convert integer to string
Params: x is the int to be converted,
str is the string into which to write
Returns: length of the string
**************************************************/
int convIntToStr(char * str, int x)
{
sprintf(str, “%d”, x);
return (strlen(str));
}
COSC 350 SYSTEM SOFTWARE, FALL 2020
2
Task #2. In Task#8 in Lab3, you wrote a program to encode a file with character to a file with
ASCII code number. Write decoding program which covert output of Task#8 in Lab3 to original
input file.
Task #3.1. Write a simple program called hello.c and compile it and create executable file
named hello.
Write a C program for sequence of following task.
• By using system call, build following directory structure
• By using system calls, copy hello file under ~/Dir2/Dir12/
• By using system calls, make a symbolic link named toDir12 to directory Dir12
• By using system calls, make a symbolic link named toHello to executable file
~/Dir12/hello
Task#3.2. (Test for Task #5.1) Execute hello by using symbolic link toHello. Try to delete a file,
make directory by using symbolic link toDir21.
COSC 350 SYSTEM SOFTWARE, FALL 2020
3
Task 4. Write your own mv named MyMv
By using bash command mv, you can move a file from current directory to another directory.
Write your own mv called MyMv by using system calls link() and unlink(). Your program named
MyMv can move a file from a current directory to a directory. Your program receives two
arguments: file name and path to a directory where the file need to move, or file name and
path to directory with a file name.
If the second argument is a directory, move a file to the directory. If the second argument is not
a directory, move file to directory as a file name.
Ex)
• Move a file foo to under directory ~/separk/cosc350
o ./MyMv foo ~/separk/cosc350
• Move a file foo to under directory ~/separk/cosc350 named abc if there is no directory
named abc
o ./MyMv foo ~/separk/cosc350/abc
• Move a file foo to under directory ~/separk/cosc350 named foo if there is no directory
named foo
o ./MyMv foo ~/separk/cosc350/foo