0x00. C - Hello, World
Concepts
Resources
Learning Objectives
At the end of this project, you are expected to be able to explain to anyone, without the help of Google
General
Why C programming is awesome
Who invented C
Who are Dennis Ritchie, Brian Kernighan and Linus Torvalds
What happens when you type
gcc main.cWhat is an entry point
What is
mainHow to print text using
printf, puts, putcharHow to get the size of a specific type using the unary operator
sizeofHow to compile using
gccWhat is the default program name when compiling with
gccWhat is the official C coding style and how to check your code with
betty-styleHow to find the right header to include in your source code when using a standard library function
How does the
mainfunction influence the return value of the program
Requirements
C
Allowed editors:
vi, vim, emacsAll your files will be compiled on Ubuntu 20.04 LTS using gcc, using the options
-Wall -Werror -Wextra -pedantic -std=gnu89All your files should end with a new line
A
README.mdfile at the root of the repo, containing a description of the repositoryA
README.mdfile, at the root of the folder of this project, containing a description of the projectThere should be no errors and no warnings during compilation
You are not allowed to use
systemYour code should use the Betty style. It will be checked using betty-style.pl and betty-doc.pl
Shell Scripts
Allowed editors:
vi, vim, emacsAll your scripts will be tested on Ubuntu 20.04 LTS
All your scripts should be exactly two lines long (
$ wc -l file should print 2)All your files should end with a new line
The first line of all your files should be exactly
#!/bin/bash
Betty Linter
To run the Betty linter just with command betty [filename]
Go to Betty Repository
Clone the repo to your local machine
cdto the Betty directoryInstall the linter with
sudo ./install.shemacs or via new file calledbetty, and copy the script below:- #!/bin/bash # Simply a wrapper script to keep you from having to use betty-style # and betty-doc separately on every item. # Originally by Tim Britton (@wintermanc3r), multiargument added by # Larry Madeo (@hillmonkey) BIN_PATH="/usr/local/bin" BETTY_STYLE="betty-style" BETTY_DOC="betty-doc" if [ "$#" = "0" ]; then echo "No arguments passed." exit 1 fi for argument in "$@" ; do echo -e "\n========== $argument ==========" ${BIN_PATH}/${BETTY_STYLE} "$argument" ${BIN_PATH}/${BETTY_DOC} "$argument" done
Once saved, exit file and change permissions to apply to all users with
chmod a+x bettyMove the
bettyfile into/bin/directory or somewhere else in your$PATHwithsudo mv betty /bin/
You can now type betty [filename] to run the Betty linter!
Tasks
Source Code
main.c
gcc options
0. Preprocessor
Write a script that runs a C file through the preprocessor and save the result into another file.
The C file name will be saved in the variable
$CFILEThe output should be saved in the file
c
1. Compiler
Write a script that compiles a C file but does not link.
The C file name will be saved in the variable
$CFILEThe output file should be named the same as the C file, but with the extension
.oinstead of.cExample: if the C file is
main.c, the output file should bemain.o
2. Assembler
Write a script that generates the assembly code of a C code and save it in an output file.
The C file name will be saved in the variable
$CFILEThe output file should be named the same as the C file, but with the extension
.sinstead of.cExample: if the C file is
main.c, the output file should bemain.s
3. Name
Write a script that compiles a C file and creates an executable named cisfun.
The C file name will be saved in the variable
$CFILE
4. Hello, puts
Write a C program that prints exactly "Programming is like building a multilingual puzzle, followed by a new line.
Use the function
putsYou are not allowed to use
printfYour program should end with the value
0
5. Hello, printf
Write a C program that prints exactly with proper grammar, but the outcome is a piece of art,, followed by a new line.
Use the function
printfYou are not allowed to use the function
putsYour program should return
0Your program should compile without warning when using the
-Wall gccoption
6. Size is not grandeur, and territory does not make a nation
Write a C program that prints the size of various types on the computer it is compiled and run on
You should produce the same output as in the example
Warnings are not allowed
Your program should return
0You might have to install the package
libc6-dev-i386on your Linux to test the-m32 gccoption
7. Intel
Write a script that generates the assembly code (intel syntax) of a C code and save it in an output file
The C file name will be saved in the variable
$CFILEThe output file should be named the same as the C file, but with the extension
.sinstead of.cExample: if the file is
main.c, the ouput file should bemain.s
8. UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity
Write a C program that prints exactly and that piece of art is useful" - Dora Korpar, 2015-10-19, followed by a new line, to the standard error.
You are not allowed to use any functions listed in the NAME section of the
man(3)printforman(3)putsYour program should return 1
Your program should compile without any warnings when using the
-Wall gccoption
Repository
GitHub repository: alx-low_level_programming
Directory: 0x00-hello_world
File: 0-preprocessor 1-compiler 2-assembler 3-name 4-puts.c 5-printf.c 6-size.c 100-intel 101-quote.c