Question: Assignment 1 : Base 6 4 In this assignment, you will write a simple base 6 4 encoding utility to familiarize yourself with the basics
Assignment : Base
In this assignment, you will write a simple base encoding utility to familiarize yourself with the basics of C programming. You will be using, exclusively, a small subset of the C standard library to accomplish this task. You will practice:
Parsing commandline arguments
Using the standard io library features
Handling errors
Manipulating data and working with arrays
Reading and understanding manpage documentation
Learning Outcomes
How to write a C program to solve a problem? Module MLO
How can programs invoke OS services using system calls? Module MLO
How do you interact with the user in C programs? Module MLO
How are C programs transformed into an executable form? Module MLO
Specification
You will write a program which meets the following specification, presented in a manpage format,
NAME
base Base encode data and print to standard output
SYNOPSIS
baseFILE
DESCRIPTION
Base encode FILE, or standard input, and output to standard output.
With no FILE, or if FILE is read from standard input.
Encoded lines are wrapped every characters.
The data are encoded according to the standard algorithm and standard base alphabet described in RFC
STDIN
The standard input shall be used only if no FILE operand is specified, or if the FILE operand is
STDOUT
The standard output shall contain the base encoded output, wrapped to characters.
STDERR
The standard error shall be used only for error reporting. All errors must be reported to standard error.
EXIT STATUS
if successful.
if an error occurs.
Please refer to man for a detailed breakdown of how man pages are structured. If you are not familiar with man pages, they are locally installed operating system documentation, and can be accessed using the man command while logged into os The first place to start learning to read man pages is to read the documentation on the man pager, itself: $ man man. Please note, man pages are specific to the system they are onwhile online man pages can be a great quick reference, always double check local man pages for things that may differ. There are often critical differences between the two.
You will write a program named base which performs base encoding on its input. Input to be base encoded may be provided either via standard input, or via a file where the name of the file is provided as a commandline argument. As a special case, if the file name is standard input will be used. This is a widely held convention with POSIX utilitiesin the event that a user wished to actually provide the file named as input, they would simply need to disambiguate by providing additional path information, as in
Some starter code is provided
Selected Topics
Program Arguments
Standard Streams
Exit Status
Understanding Encoding
Constraints
Your program may not use a feature of the C language called Variable Length Arrays VLAs There are arrays that are declared with extents that are not compiletime constant expressions; for example,
sizet i strleninput;
char bufferi; Prohibited!
strcpybuffer input;
VLAs are generally considered a bad programming practice, and are a common cause of serious bugs and security holesthey can also be a source of difficulttodiagnose issues in your own program, so we will avoid using them. Additionally, many compilers just dont support them because they are complicated to implement with a lot of edge cases. You can use the compiler option Werrorvla when compiling your code the makefile will do this automatically for you to emit an error if you accidentally use a VLA.
Note that, macros are commonly used to avoid magic numbers in array extents, as in
#define BUFSIZE
char bufBUFSIZE;
The above is not an example of VLA, because macro replacement happens during preprocessingby the time the C compiler is involved, all it sees is char bufand is a compiletime constant expression. The rule of thumb is if you reference an actual variable not a macro or call a function, its not a compiletime constant expression!
Your program must run in constant, O space complexitythis means, regardless of the size of the input provided, your program must use the same amount of memory to process it This precludes, for example, buffering the entire input into a dynamically resized array and then processing itdont use malloc you dont need it
Your program must compile against the c language standard, using the compiler option stdcthe makefile will also handle this for you We are not using the gnu standard in this class, as it is more relaxed on constraints and less likely to help you catch common programming mistakes.
When your program encounters an error such as failure to open a file, input, or output error it must print an error message to stderr, and exit with a nonzero exit status
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
