Question
Each student is tasked with implementing a C program that can process any input received from the standard input (stdin), convert each byte of data
Each student is tasked with implementing a C program that can process any input received from the standard input (stdin), convert each byte of data to its binary representation, and display the result on the standard output (stdout).
1.1 Objectives
Make a "simple" program in C
Utilize C functions and libraries effectively
Process input from Standard Input (stdin)
Send output to Standard Output (stdout) 2 Detailed Description
2.1 Introduction
The C programming language, while older than high-level languages like C++ and Java, remains foundational in systems programming due to its close relationship with underlying hardware and operating systems. A fundamental aspect of C is its model of input and output. While modern languages often provide abstractions for these operations, in C, we rely on foundational functions such as getchar(), putchar(), scanf(), and printf(). Each of these functions has unique syntax and behavior, and mastering them is crucial for effective C programming.
In this project, you will be tasked with accepting any form of input data from the standard input (stdin), converting each byte to its binary representation, and then displaying the result on the standard output (stdout). This exercise not only enhances your understanding of C's input/output model but also deepens your appreciation of data representation at a foundational level.
2.2 C Input/Output
At its core, C handles data streams through the notion of "files". Notably, the default data streams, stdin and stdout, are treated as such "files". These, however, are pseudo-files. In standard operations, stdin is connected 1 to the keyboard and serves as the primary data input stream, while stdout corresponds to the console or terminal screen, acting as the main data output stream. This means functions like scanf, printf, and their kin, by default, interact with these pseudo-files, unless specified otherwise. While advanced usages might involve redirecting these streams to other files or even network sockets, for this project, we'll focus on the conventional behavior.
A crucial aspect of reading data streams in C is recognizing the end of data. This is typically indicated by an Endof-File (EOF) marker. In Unix environments, pressing [cntl-d] produces the ASCII code 04, symbolizing this EOF or End of Transmission. Most C programs, when processing input, will continue reading data until encountering this EOF marker. Conversely, during output operations, developers generally don't need to specify the EOF as operating systems manage this detail when generating or reading files.
2.3 What to do
Develop a C program named "intro" that functions as a universal converter. Your program should:
Accept any data input from stdin.
Convert each byte of the input to its corresponding binary representation.
Output the binary conversion result to stdout.
Introduce a newline in the output after every eight (8) binary values.
2.4 Compiling your program
Please use gcc to compile and submit your program. specifically use the following command to compile your program:
gcc -std=c99 -Wall -pedantic-errors -Werror -o intro
Replace with the filename for your source code. I chose intro.c for mine, and I suggest you do the same. We'll explain the other options in class, but the result should be a program called intro All your C programs in this course should be written in correct C, which means they must compile and run correctly when compiled with the compiler gcc, with the options -std=c99 -Wall, -pedantic-errors, and -Werror. Except as noted below, you may use any C language features in your project that have been covered in class, or that are in the chapters covered so far and during the time this project is assigned, so long as your program works successfully using the compiler options mentioned above.
2.5 Example output
2.5.1 Example 1
project0> cat gfa1.txt
Hello, World
project0> ./intro < gfa1.txt
01001000 01100101 01101100 01101100 01101111 00101100 00100000 01010111 01101111 01110010 01101100 01100100 project0> cat gfa2.txt
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
project0> ./intro < gfa2.txt
01000001 01000010 01000011 01000100 01000101 01000110 01000111 01001000 01001001 01001010 01001011 01001100 01001101 01001110 01001111 01010000 01010001 01010010 01010011 01010100 01010101 01010110 01010111 01011000 01011001 01011010 00110000 00110001 00110010 00110011 00110100 00110101 00110110 00110111 00111000 00111001 00001010
3. Submission
Project should be submitted via the submit program on tpaclinux. Follow these instructions to turn in your project.
You should submit the following files:
intro.c
intro.h (optional)
any other source files your project needs
The following submission directions use the command-line submit program that we will use for all projects this semester. 1. Use the command-line submit program to turn-in your project files:
submit INTRO intro.c intro.h
4. Grading
While this rubric is subject to change based on class performance, the current grading rubric for this assignment is as follows: Correctness 50, Completeness 40, Code Quality 10.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started