ALX SE Task - Sprint 1
ALX SE Task - Sprint 1
Shell, navigation
Quiz questions
Great! You've completed the quiz successfully! Keep going! (Show quiz)
Tasks
0. Create me!
mandatory
Advices:
1. More of me
mandatory
Advices:
2. To old
mandatory
3. Not here
mandatory
Advices:
Done? Help Check your code Ask for a new correction Get a sandbox QA Review
4. Not anymore
mandatory
Advices:
5. Organization is key!
mandatory
Advices:
6. No need
mandatory
Advices:
In a nutshell…
Concepts
For this project, we expect you to look at these concepts:
• Shell
• Using Emacs as editor
• The Framework
Congrats!
Now you know how to navigate into a Unix system!
It’s time to test and decide what will be your favorite text editor on your sandbox: Emacs or Vi.
During this project you will play with Emacs.
Resources
Read or watch:
Learning Objectives
At the end of this project, you are expected to be able to explain to anyone, without the help of
Google:
General
• What is Emacs
• Who is Richard Stallman
• How to open and save files
• What is a buffer and how to switch from one to the other
• How to use the mark and the point to set the region
• How to cut and paste lines and regions
• How to search forward and backward
• How to invoke commands by name
• How to undo
• How to cancel half-entered commands
• How to quit Emacs
Copyright - Plagiarism
• You are tasked to come up with solutions for the tasks below yourself to meet with the
above learning objectives.
• You will not be able to meet the objectives of this or any following project by copying and
pasting someone else’s work.
• You are not allowed to publish any content of this project.
• Any form of plagiarism is strictly forbidden and will result in removal from the program.
Requirements
• All tasks must be done inside the sandbox Ubuntu 20.04
• Your sandbox must be available at the end of this project - the Checker will access to
it at midnight for running the correction!
• The answer of a task must be in a specific file
• Each answer file must contain only the command to execute in Emacs for solving the
task. Example: “What is the command to write buffer to a specified file?” -> the file should
contain only C-x C-w
Quiz questions
Great! You've completed the quiz successfully! Keep going! (Show quiz)
Tasks
0. Create your answer directory
mandatory
1. Opening
mandatory
root@hex:~# ls -l /root/0x01_emacs/opening
2. Saving
mandatory
3. Cutting
mandatory
4. Pasting
mandatory
5. Searching
mandatory
6. Undoing
mandatory
7. Quitting
mandatory
Score: 100.0% (Checks completed: 100.0%)
What is the command to quit Emacs?
Write the answer into the file /root/0x01_emacs/quitting.
[Optional] Vagrant
DevOpsVirtual machine
In a nutshell…
Concepts
For this project, we expect you to look at this concept:
Resources
Read or watch:
• Virtual machine
• man uname
Learning Objectives
At the end of this project, you are expected to be able to explain to anyone, without the help of
Google:
General
• What is a virtual machine
• What is Vagrant
• Who wrote Vagrant
• What is Ubuntu
• What does “Ubuntu” mean
• How to use VMs with Vagrant
• What does the command uname do
Copyright - Plagiarism
• You are tasked to come up with solutions for the tasks below yourself to meet with the
above learning objectives.
• You will not be able to meet the objectives of this or any following project by copying and
pasting someone else’s work.
• You are not allowed to publish any content of this project.
• Any form of plagiarism is strictly forbidden and will result in removal from the program.
Requirements
General
• A README.md file at the root of the repo, containing a description of the repository
• A README.md file, at the root of the folder of this project (i.e. 0x00-vagrant), describing
what this project is about
More Info
Install git
If git is not already installed on your terminal:
Basic usage
At the end of this project you should be able to reproduce and understand these command lines:
$ touch test
Quiz questions
Great! You've completed the quiz successfully! Keep going! (Show quiz)
Tasks
0. Create and setup your Git and GitHub account
#advanced
• Configure your basic info (name, email) on your local machine – they will be part of your
commits. Tips
On GitHub.com:
• Using the graphic interface on the website, create the repository (if it’s not done yet)
o Description: This is my first repository as a full-stack engineer
o Public repo: zero_day
o No README, .gitignore, or license
Good job!
You pushed your first file in your first repository of the first task of your first School project.
Repo:
In a nutshell…
Resources
Read or watch:
• Basic vi Commands
Learning Objectives
At the end of this project, you are expected to be able to explain to anyone, without the help of
Google:
General
• What is vi
• Who is Bill Joy
• How to start and exit vi
• What are the command and insert modes, and how to switch from one to the other
• How to edit text
• How to cut and paste lines
• How to search forward and backward
• How to undo
• How to quit vi
Copyright - Plagiarism
• You are tasked to come up with solutions for the tasks below yourself to meet with the
above learning objectives.
• You will not be able to meet the objectives of this or any following project by copying and
pasting someone else’s work.
• You are not allowed to publish any content of this project.
• Any form of plagiarism is strictly forbidden and will result in removal from the program.
Requirements
• All tasks must be done inside the sandbox Ubuntu 20.04
• Your sandbox must be available at the end of this project - the Checker will access to
it just after the deadline to run the correction!
• The answer of a task must be in a specific file
• Each answer file must contain only the command to execute in Emacs for solving the
task. Example: “What is the command to quit without saving changes?” -> the file should
contain only :q!
Quiz questions
Great! You've completed the quiz successfully! Keep going! (Show quiz)
Tasks
0. Create your answer directory
mandatory
1. Inserting
mandatory
root@hex:~# ls -l /root/0x02_vi/inserting
root@hex:~#
2. Cutting
mandatory
4. Undoing
mandatory
5. Exiting
mandatory
• By: Guillaume
• Weight: 1
• Project over - took place from Nov 29, 2022 6:00 AM to Nov 30, 2022 6:00 AM
• An auto review will be launched at the deadline
In a nutshell…
Concepts
For this project, we expect you to look at these concepts:
• Right-engineering, right-documenting
• Source code management
• Git and Github cheat sheet - Everything in less than 30 seconds
Resources
Read or watch:
Resources for advanced tasks (Read only after finishing the mandatory tasks):
• Learning branching
• Effective pull requests and other good practices for teams using GitHub
Learning Objectives
At the end of this project, you are expected to be able to explain to anyone, without the help of
Google:
General
• What is source code management
• What is Git
• What is GitHub
• What is the difference between Git and GitHub
• How to create a repository
• What is a README
• How to write good READMEs
• How to commit
• How to write helpful commit messages
• How to push code
• How to pull updates
• How to create a branch
• How to merge branches
• How to work as collaborators on a project
• Which files should and which files should not appear in your repo
Copyright - Plagiarism
• You are tasked to come up with solutions for the tasks below yourself to meet with the
above learning objectives.
• You will not be able to meet the objectives of this or any following project by copying and
pasting someone else’s work.
• You are not allowed to publish any content of this project.
• Any form of plagiarism is strictly forbidden and will result in removal from the program.
Requirements
General
• A README.md file at the root of the alx-zero_day repo, containing a description of the
repository
• A README.md file, at the root of the folder of this project (i.e. 0x03-git), describing what
this project is about
• Do not use GitHub’s web UI, but the command line to perform the exercise (except for
operations that can not possibly be done any other way than through the web UI). You
won’t be able to perform many of the task requirements on the web UI, and you should
start getting used to the command line for simple tasks because many complex tasks can
only be done via the command line.
• Your answer files should only contain the command, and nothing else
More Info
Basic usage
At the end of this project you should be able to reproduce and understand these command lines:
$ touch test
Quiz questions
Great! You've completed the quiz successfully! Keep going! (Show quiz)
Tasks
0. Create and setup your Git and GitHub account
mandatory
Step 0 - Create an account on GitHub [if you do not have one already]
You will need a GitHub account for all your projects at ALX. If you do not already have a
github.com account, you can create an account for free here
• Name: alx-zero_day
• Description: I'm now a ALX Student, this is my first repository as a full-
stack engineer
• Public repo
• No README, .gitignore, or license
root@896cf839cf9a:/# cd alx-zero_day/
root@896cf839cf9a:/alx-zero_day#
• Create the file README.md with the content My first readme. Tips
My first readme
• Add this new file to git, commit the change with this message “My first commit” and push
to the remote server / origin
To https://github.com/{YOUR_USERNAME}/alx-zero_day.git
Good job!
You pushed your first file in your first repository of the first task of your first ALX School
project.
You can now check your repository on GitHub to see if everything is good.
Repo:
And important part: Make sure your commit and push your code to Github - otherwise the
Checker will always fail.
Repo:
Repo:
The purpose of a branch is to isolate your work from the main code base of your project and/or
from your co-workers’ work.
For this project, create a branch update_script and in this branch:
Perfect! You did an amazing update in your project and it’s isolated correctly from
the main branch.
Ho wait, your manager needs a quick fix in your project and it needs to be deployed now:
• Get all changes of the main branch locally (i.e. your README.md file will be updated)
• Create a new file up_to_date at the root of your directory and in it, write the git
command line used
• Add up_to_date to git, commit (message: “How to be up to date in git”), and push to the
origin
Repo:
As you can see, you have conflicts between two branches on the same file.
Your goal now is to resolve conflicts by using the version of the branch update_script, and
push the result to the origin.
At the end, you should have all your work from the branch update_script (new file and two
updated files) and all latest main commits (new files, delete folder, etc.), without conflicts.
Repo:
• gcc
• printf (3)
• puts
• putchar
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.c
• What is an entry point
• What is main
• How to print text using printf, puts and putchar
• How to get the size of a specific type using the unary operator sizeof
• How to compile using gcc
• What is the default program name when compiling with gcc
• What is the official C coding style and how to check your code with betty-style
• How to find the right header to include in your source code when using a standard library
function
• How does the main function influence the return value of the program
Copyright - Plagiarism
• You are tasked to come up with solutions for the tasks below yourself to meet with the
above learning objectives.
• You will not be able to meet the objectives of this or any following project by copying and
pasting someone else’s work.
• You are not allowed to publish any content of this project.
• Any form of plagiarism is strictly forbidden and will result in removal from the program.
Requirements
C
• Allowed editors: vi, vim, emacs
• All your files will be compiled on Ubuntu 20.04 LTS using gcc, using the options -Wall -
Werror -Wextra -pedantic -std=gnu89
• All your files should end with a new line
• A README.md file at the root of the repo, containing a description of the repository
• A README.md file, at the root of the folder of this project, containing a description of the
project
• There should be no errors and no warnings during compilation
• You are not allowed to use system
• Your code should use the Betty style. It will be checked using betty-style.pl and betty-
doc.pl
Shell Scripts
• Allowed editors: vi, vim, emacs
• All 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
More Info
Betty linter
To run the Betty linter just with command betty <filename>:
#!/bin/bash
BIN_PATH="/usr/local/bin"
BETTY_STYLE="betty-style"
BETTY_DOC="betty-doc"
exit 1
fi
for argument in "$@" ; do
${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 betty
• Move the betty file into /bin/ directory or somewhere else in your $PATH with sudo mv
betty /bin/
You can now type betty <filename> to run the Betty linter!
Quiz questions
Great! You've completed the quiz successfully! Keep going! (Show quiz)
Tasks
0. Preprocessor
mandatory
#include <stdio.h>
/**
*/
int main(void)
return (0);
julien@ubuntu:~/c/0x00$ ./0-preprocessor
julien@ubuntu:~/c/0x00$ tail c
# 942 "/usr/include/stdio.h" 3 4
# 2 "main.c" 2
# 3 "main.c"
int main(void)
return (0);
julien@ubuntu:~/c/0x00$
Repo:
1. Compiler
mandatory
#include <stdio.h>
/**
*/
int main(void)
{
return (0);
julien@ubuntu:~/c/0x00$ ./1-compiler
julien@ubuntu:~/c/0x00$ ls
^?ELF^B^A^A^@^@^@^@^@^@^@^@^@^A^@>^@^A^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^
@^P^B^@^@^@^@^@^@^@^@^@^@@^@^@^@^@^@@^@^K^@^H^@UHM-^IM-eM-8^@^@^@^@]M-C^@GC
C: (Ubuntu 5.4.0-6ubuntu1~16.04.2) 5.4.0 20160609^@^T^@^@^@^@^@^@^@^AzR^@^A
x^P^A^[^L^G^HM-^P^A^@^@^\^@^@^@^\^@^@^@^@^@^@^@^K^@^@^@^@A^N^PM-^F^BC^M^FF^
L^G^H^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^A^@^@^@^D^@M-qM
-^?^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^C^@^A^@^@^@^@^@^@^@^@^@^@^@^@^@
^@^@^@^@^@^@^@^@^C^@^B^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^C^@^C^@^@^
@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^C^@^E^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
^@^@^@^@^@^C^@^F^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^C^@^D^@^@^@^@^@^
@^@^@^@^@^@^@^@^@^@^@^@^H^@^@^@^R^@^A^@^@^@^@^@^@^@^@^@^K^@^@^@^@^@^@^@^@ma
in.c^@main^@^@^@^@ ^@^@^@^@^@^@^@^B^@^@^@^B^@^@^@^@^@^@^@^@^@^@^@^@.symtab^
@.strtab^@.shstrtab^@.text^@.data^@.bss^@.comment^@.note.GNU-stack^@.rela.e
h_frame^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^[^@^
@^@^A^@^@^@^F^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@@^@^@^@^@^@^@^@^K^@^@^@^@^@^@^@^
@^@^@^@^@^@^@^@^A^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@!^@^@^@^A^@^@^@^C^@^@^@^@^@^
@^@^@^@^@^@^@^@^@^@K^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^A^@^@^@^
@^@^@^@^@^@^@^@^@^@^@^@'^@^@^@^H^@^@^@^C^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@K^@^@
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^A^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@,
^@^@^@^A^@^@^@0^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@K^@^@^@^@^@^@^@5^@^@^@^@^@^@^@
^@^@^@^@^@^@^@^@^A^@^@^@^@^@^@^@^A^@^@^@^@^@^@^@5^@^@^@^A^@^@^@^@^@^@^@^@^@
^@^@^@^@^@^@^@^@^@^@M-^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^A^@^
@^@^@^@^@^@^@^@^@^@^@^@^@^@J^@^@^@^A^@^@^@^B^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@M
-^@^@^@^@^@^@^@^@8^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^H^@^@^@^@^@^@^@^@^@^@^@^@^
@^@^@E^@^@^@^D^@^@^@@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@M- ^A^@^@^@^@^@^@^X^@^@^
@^@^@^@^@ ^@^@^@^F^@^@^@^H^@^@^@^@^@^@^@^X^@^@^@^@^@^@^@^Q^@^@^@^C^@^@^@
^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@M-8^A^@^@^@^@^@^@T^@^@^@^@^@^@^@^@^@^@^@^@^
@^@^@^A^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^A^@^@^@^B^@^@^@^@^@^@^@^@^@^@^@^@^@^@
^@^@^@^@^@M-8^@^@^@^@^@^@^@M-X^@^@^@^@^@^@^@
^@^@^@^H^@^@^@^H^@^@^@^@^@^@^@^X^@^@^@^@^@^@^@ ^@^@^@^C^@^@^@^@^@^@^@^@^@^
@^@^@^@^@^@^@^@^@^@M-^P^A^@^@^@^@^@^@^M^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^A^@^@
^@^@^@^@^@^@^@^@^@^@^@^@^@julien@ubuntu:~/c/0x00$
Repo:
2. Assembler
mandatory
#include <stdio.h>
/**
*/
int main(void)
return (0);
julien@ubuntu:~/c/0x00$ ./2-assembler
julien@ubuntu:~/c/0x00$ ls
.file "main.c"
.text
.globl main
main:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
.cfi_def_cfa_register 6
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.section .note.GNU-stack,"",@progbits
julien@ubuntu:~/c/0x00$
Repo:
3. Name
mandatory
#include <stdio.h>
/**
*/
int main(void)
return (0);
julien@ubuntu:~/c/0x00$ ./3-name
julien@ubuntu:~/c/0x00$ ls
julien@ubuntu:~/c/0x00$
Repo:
4. Hello, puts
mandatory
julien@ubuntu:~/c/0x00$ echo $?
julien@ubuntu:~/c/0x00$
Repo:
5. Hello, printf
mandatory
Score: 100.0% (Checks completed: 100.0%)
Write a C program that prints exactly with proper grammar, but the outcome is a piece
of art,, followed by a new line.
julien@ubuntu:~/c/0x00$ ./a.out
julien@ubuntu:~/c/0x00$ echo $?
julien@ubuntu:~/c/0x00$
Repo:
julien@ubuntu:~/c/0x00$ ./size32
julien@ubuntu:~/c/0x00$ ./size64
julien@ubuntu:~/c/0x00$ echo $?
julien@ubuntu:~/c/0x00$
Repo:
7. Intel
#advanced
#include <stdio.h>
/**
*/
int main(void)
{
return (0);
julien@ubuntu:~/c/0x00$ ./100-intel
.file "main.c"
.intel_syntax noprefix
.text
.globl main
main:
.LFB0:
.cfi_startproc
push rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
.cfi_def_cfa_register 6
mov eax, 0
pop rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.section .note.GNU-stack,"",@progbits
julien@ubuntu:~/c/0x00$
Repo:
• You are not allowed to use any functions listed in the NAME section of the man
(3) printf or man (3) puts
• Your program should return 1
• Your program should compile without any warnings when using the -Wall gcc option
julien@ubuntu:~/c/0x00$ ./quote
julien@ubuntu:~/c/0x00$ echo $?
julien@ubuntu:~/c/0x00$ cat q
julien@ubuntu:~/c/0x00$
Repo:
Learning Objectives
At the end of this project, you are expected to be able to explain to anyone, without the help of
Google:
General
• What are the arithmetic operators and how to use them
• What are the logical operators (sometimes called boolean operators) and how to use
them
• What the the relational operators and how to use them
• What values are considered TRUE and FALSE in C
• What are the boolean operators and how to use them
• How to use the if, if ... else statements
• How to use comments
• How to declare variables of types char, int, unsigned int
• How to assign values to variables
• How to print the values of variables of type char, int, unsigned int with printf
• How to use the while loop
• How to use variables with the while loop
• How to print variables using printf
• What is the ASCII character set
• What are the purpose of the gcc flags -m32 and -m64
Copyright - Plagiarism
• You are tasked to come up with solutions for the tasks below yourself to meet with the
above learning objectives.
• You will not be able to meet the objectives of this or any following project by copying and
pasting someone else’s work.
• You are not allowed to publish any content of this project.
• Any form of plagiarism is strictly forbidden and will result in removal from the program.
Requirements
General
• Allowed editors: vi, vim, emacs
• All your files will be compiled on Ubuntu 20.04 LTS using gcc, using the options -Wall -
Werror -Wextra -pedantic -std=gnu89
• All your files should end with a new line
• A README.md file, at the root of the folder of the project
• There should be no errors and no warnings during compilation
• You are not allowed to use system
• Your code should use the Betty style. It will be checked using betty-style.pl and betty-
doc.pl
Quiz questions
Great! You've completed the quiz successfully! Keep going! (Show quiz)
Tasks
0. Positive anything is better than negative nothing
mandatory
julien@ubuntu:~/0x01$ ./0-positive_or_negative
-520693284 is negative
julien@ubuntu:~/0x01$ ./0-positive_or_negative
-973398895 is negative
julien@ubuntu:~/0x01$ ./0-positive_or_negative
-199220452 is negative
julien@ubuntu:~/0x01$ ./0-positive_or_negative
561319348 is positive
julien@ubuntu:~/0x01$ ./0-positive_or_negative
561319348 is positive
julien@ubuntu:~/0x01$ ./0-positive_or_negative
266853958 is positive
julien@ubuntu:~/0x01$ ./0-positive_or_negative
-48147767 is negative
julien@ubuntu:~/0x01$ ./0-positive_or_negative
0 is zero
julien@ubuntu:~/0x01$
Repo:
julien@ubuntu:~/0x01$ ./1-last_digit
julien@ubuntu:~/0x01$ ./1-last_digit
julien@ubuntu:~/0x01$ ./1-last_digit
julien@ubuntu:~/0x01$ ./1-last_digit
julien@ubuntu:~/0x01$ ./1-last_digit
julien@ubuntu:~/0x01$ ./1-last_digit
julien@ubuntu:~/0x01$ ./1-last_digit
julien@ubuntu:~/0x01$ ./1-last_digit
julien@ubuntu:~/0x01$ ./1-last_digit
julien@ubuntu:~/0x01$ ./1-last_digit
julien@ubuntu:~/0x01$ ./1-last_digit
julien@ubuntu:~/0x01$ ./1-last_digit
julien@ubuntu:~/0x01$
Repo:
• You can only use the putchar function (every other function (printf, puts, etc…) is
forbidden)
• All your code should be in the main function
• You can only use putchar twice in your code
abcdefghijklmnopqrstuvwxyz
julien@ubuntu:~/0x01$
Repo:
• You can only use the putchar function (every other function (printf, puts, etc…) is
forbidden)
• All your code should be in the main function
• You can only use putchar three times in your code
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$
julien@ubuntu:~/0x01$
Repo:
julien@ubuntu:~/0x01$ ./4-print_alphabt
abcdfghijklmnoprstuvwxyz
julien@ubuntu:~/0x01$
Repo:
julien@ubuntu:~/0x01$ ./5-print_numbers
0123456789
julien@ubuntu:~/0x01$
Repo:
julien@ubuntu:~/0x01$ ./6-print_numberz
0123456789
julien@ubuntu:~/0x01$
Repo:
• You can only use the putchar function (every other function (printf, puts, etc…) is
forbidden)
• All your code should be in the main function
• You can only use putchar twice in your code
julien@ubuntu:~/0x01$ ./7-print_tebahpla
zyxwvutsrqponmlkjihgfedcba
julien@ubuntu:~/0x01$
Repo:
julien@ubuntu:~/0x01$ ./8-print_base16
0123456789abcdef
julien@ubuntu:~/0x01$
Repo:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9$
julien@ubuntu:~/0x01$
Repo:
julien@ubuntu:~/0x01$ ./100-print_comb3
01, 02, 03, 04, 05, 06, 07, 08, 09, 12, 13, 14, 15, 16, 17, 18, 19, 23, 24,
25, 26, 27, 28, 29, 34, 35, 36, 37, 38, 39, 45, 46, 47, 48, 49, 56, 57, 58,
59, 67, 68, 69, 78, 79, 89
julien@ubuntu:~/0x01$
Repo:
julien@ubuntu:~/0x01$ ./101-print_comb4
012, 013, 014, 015, 016, 017, 018, 019, 023, 024, 025, 026, 027, 028, 029,
034, 035, 036, 037, 038, 039, 045, 046, 047, 048, 049, 056, 057, 058, 059,
067, 068, 069, 078, 079, 089, 123, 124, 125, 126, 127, 128, 129, 134, 135,
136, 137, 138, 139, 145, 146, 147, 148, 149, 156, 157, 158, 159, 167, 168,
169, 178, 179, 189, 234, 235, 236, 237, 238, 239, 245, 246, 247, 248, 249,
256, 257, 258, 259, 267, 268, 269, 278, 279, 289, 345, 346, 347, 348, 349,
356, 357, 358, 359, 367, 368, 369, 378, 379, 389, 456, 457, 458, 459, 467,
468, 469, 478, 479, 489, 567, 568, 569, 578, 579, 589, 678, 679, 689, 789
julien@ubuntu:~/0x01$
Repo:
julien@ubuntu:~/0x01$ ./102-print_comb5
00 01, 00 02, 00 03, 00 04, 00 05, 00 06, 00 07, 00 08, 00 09, 00 10, 00 11
, [...] 40 91, 40 92, 40 93, 40 94, 40 95, 40 96, 40 97, 40 98, 40 99, 41 4
2, 41 43, 41 44, 41 45, 41 46, 41 47, 41 48, 41 49, 41 50, 41 51, 41 52, 41
53 [...] 93 95, 93 96, 93 97, 93 98, 93 99, 94 95, 94 96, 94 97, 94 98, 94
99, 95 96, 95 97, 95 98, 95 99, 96 97, 96 98, 96 99, 97 98, 97 99, 98 99
Repo:
• GitHub repository: alx-low_level_programming
• Directory: 0x01-variables_if_else_while
• File: 102-print_comb5.c
0x02. C - Functions, nested loops
C
In a nutshell…
Resources
Read or watch:
Learning Objectives
At the end of this project, you are expected to be able to explain to anyone, without the help of
Google:
General
• What are nested loops and how to use them
• What is a function and how do you use functions
• What is the difference between a declaration and a definition of a function
• What is a prototype
• Scope of variables
• What are the gcc flags -Wall -Werror -pedantic -Wextra -std=gnu89
• What are header files and how to to use them with #include
Requirements
General
• Allowed editors: vi, vim, emacs
• All your files will be compiled on Ubuntu 20.04 LTS using gcc, using the options -Wall -
Werror -Wextra -pedantic -std=gnu89
• All your files should end with a new line
• A README.md file, at the root of the folder of the project is mandatory
• Your code should use the Betty style. It will be checked using betty-style.pl and betty-
doc.pl
• You are not allowed to use global variables
• No more than 5 functions per file
• You are not allowed to use the standard library. Any use of functions like printf, puts,
etc… is forbidden
• You are allowed to use _putchar
• You don’t have to push _putchar.c, we will use our file. If you do it won’t be taken into
account
• In the following examples, the main.c files are shown as examples. You can use them to
test your functions, but you don’t have to push them to your repo (if you do we won’t take
them into account). We will use our own main.c files at compilation. Our main.c files
might be different from the one shown in the examples
• The prototypes of all your functions and the prototype of the function _putchar should be
included in your header file called main.h
• Don’t forget to push your header file
Copyright - Plagiarism
• You are tasked to come up with solutions for the tasks below yourself to meet with the
above learning objectives.
• You will not be able to meet the objectives of this or any following project by copying and
pasting someone else’s work.
• You are not allowed to publish any content of this project.
• Any form of plagiarism is strictly forbidden and will result in removal from the program.
More Info
You do not have to understand the call by reference (address), stack, static variables, recursions
or arrays, yet.
Quiz questions
Great! You've completed the quiz successfully! Keep going! (Show quiz)
Tasks
0. _putchar
mandatory
julien@ubuntu:~/0x02$ ./0-putchar
_putchar
julien@ubuntu:~/0x02$
Repo:
#include "main.h"
/**
* Return: Always 0.
*/
int main(void)
print_alphabet();
return (0);
julien@ubuntu:~/0x02$ ./1-alphabet
abcdefghijklmnopqrstuvwxyz
julien@ubuntu:~/0x02$
Repo:
• GitHub repository: alx-low_level_programming
• Directory: 0x02-functions_nested_loops
• File: 1-alphabet.c
#include "main.h"
/**
* Return: Always 0.
*/
int main(void)
print_alphabet_x10();
return (0);
julien@ubuntu:~/0x02$ ./2-alphabet_x10
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
abcdefghijklmnopqrstuvwxyz
julien@ubuntu:~/0x02$
Repo:
FYI: The standard library provides a similar function: islower. Run man islower to learn more.
#include "main.h"
/**
* Return: Always 0.
*/
int main(void)
int r;
r = _islower('H');
_putchar(r + '0');
r = _islower('o');
_putchar(r + '0');
r = _islower(108);
_putchar(r + '0');
_putchar('\n');
return (0);
julien@ubuntu:~/0x02$ ./3-islower
011
julien@ubuntu:~/0x02$
Repo:
FYI: The standard library provides a similar function: isalpha. Run man isalpha to learn more.
#include "main.h"
/**
* Return: Always 0.
*/
int main(void)
int r;
r = _isalpha('H');
_putchar(r + '0');
r = _isalpha('o');
_putchar(r + '0');
r = _isalpha(108);
_putchar(r + '0');
r = _isalpha(';');
_putchar(r + '0');
_putchar('\n');
return (0);
julien@ubuntu:~/0x02$ ./4-isalpha
1110
julien@ubuntu:~/0x02$
Repo:
#include "main.h"
/**
*
* Return: Always 0.
*/
int main(void)
int r;
r = print_sign(98);
_putchar(',');
_putchar(' ');
_putchar(r + '0');
_putchar('\n');
r = print_sign(0);
_putchar(',');
_putchar(' ');
_putchar(r + '0');
_putchar('\n');
r = print_sign(0xff);
_putchar(',');
_putchar(' ');
_putchar(r + '0');
_putchar('\n');
r = print_sign(-1);
_putchar(',');
_putchar(' ');
_putchar(r + '0');
_putchar('\n');
return (0);
julien@ubuntu:~/0x02$ ./5-sign
+, 1
0, 0
+, 1
-, /
julien@ubuntu:~/0x02$
Repo:
FYI: The standard library provides a similar function: abs. Run man abs to learn more.
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
int r;
r = _abs(-1);
printf("%d\n", r);
r = _abs(0);
printf("%d\n", r);
r = _abs(1);
printf("%d\n", r);
r = _abs(-98);
printf("%d\n", r);
return (0);
julien@ubuntu:~/0x02$ ./6-abs
98
julien@ubuntu:~/0x02$
Repo:
#include "main.h"
/**
* Return: Always 0.
*/
int main(void)
{
int r;
print_last_digit(98);
print_last_digit(0);
r = print_last_digit(-1024);
_putchar('0' + r);
_putchar('\n');
return (0);
julien@ubuntu:~/0x02$ ./7-last_digit
8044
julien@ubuntu:~/0x02$
Repo:
#include "main.h"
/**
* Return: Always 0.
*/
int main(void)
jack_bauer();
return (0);
00:00
00:01
00:02
00:03
00:04
00:05
00:06
00:07
00:08
00:09
23:50
23:51
23:52
23:53
23:54
23:55
23:56
23:57
23:58
23:59
julien@ubuntu:~/0x02$ ./8-24 | wc -l
1440
julien@ubuntu:~/0x02$
Repo:
• GitHub repository: alx-low_level_programming
• Directory: 0x02-functions_nested_loops
• File: 8-24_hours.c
#include "main.h"
/**
* Return: Always 0.
*/
int main(void)
times_table();
return (0);
0, 0, 0, 0, 0, 0, 0, 0, 0, 0$
0, 1, 2, 3, 4, 5, 6, 7, 8, 9$
0,..0,..0,..0,..0,..0,..0,..0,..0,..0$
0,..1,..2,..3,..4,..5,..6,..7,..8,..9$
0,..2,..4,..6,..8,.10,.12,.14,.16,.18$
0,..3,..6,..9,.12,.15,.18,.21,.24,.27$
0,..4,..8,.12,.16,.20,.24,.28,.32,.36$
0,..5,.10,.15,.20,.25,.30,.35,.40,.45$
0,..6,.12,.18,.24,.30,.36,.42,.48,.54$
0,..7,.14,.21,.28,.35,.42,.49,.56,.63$
0,..8,.16,.24,.32,.40,.48,.56,.64,.72$
0,..9,.18,.27,.36,.45,.54,.63,.72,.81$
julien@ubuntu:~/0x02$
Repo:
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
int n;
n = add(89, 9);
printf("%d\n", n);
return (0);
julien@ubuntu:~/0x02$ ./10-add
98
julien@ubuntu:~/0x02$
Repo:
#include "main.h"
/**
* Return: Always 0.
*/
int main(void)
print_to_98(0);
print_to_98(98);
print_to_98(111);
print_to_98(81);
print_to_98(-10);
return (0);
julien@ubuntu:~/0x02$ ./11-98
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 2
1, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58,
59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
97, 98
98
111, 110, 109, 108, 107, 106, 105, 104, 103, 102, 101, 100, 99, 98
81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98
-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86,
87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98
julien@ubuntu:~/0x02$
Repo:
#include "main.h"
/**
* Return: Always 0.
*/
int main(void)
print_times_table(3);
_putchar('\n');
print_times_table(5);
_putchar('\n');
print_times_table(98);
_putchar('\n');
print_times_table(12);
return (0);
julien@ubuntu:~/0x02$ ./100-times_table
0, 0, 0, 0
0, 1, 2, 3
0, 2, 4, 6
0, 3, 6, 9
0, 0, 0, 0, 0, 0
0, 1, 2, 3, 4, 5
0, 2, 4, 6, 8, 10
0, 3, 6, 9, 12, 15
0, 4, 8, 12, 16, 20
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60
0, 6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72
0, 7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84
0, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96
0, 9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108
0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120
0, 11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132
0, 12, 24, 36, 48, 60, 72, 84, 96, 108, 120, 132, 144
0,...0,...0,...0$
0,...1,...2,...3$
0,...2,...4,...6$
0,...3,...6,...9$
0,...0,...0,...0,...0,...0$
0,...1,...2,...3,...4,...5$
0,...2,...4,...6,...8,..10$
0,...3,...6,...9,..12,..15$
0,...4,...8,..12,..16,..20$
0,...5,..10,..15,..20,..25$
0,...0,...0,...0,...0,...0,...0,...0,...0,...0,...0,...0,...0$
0,...1,...2,...3,...4,...5,...6,...7,...8,...9,..10,..11,..12$
0,...2,...4,...6,...8,..10,..12,..14,..16,..18,..20,..22,..24$
0,...3,...6,...9,..12,..15,..18,..21,..24,..27,..30,..33,..36$
0,...4,...8,..12,..16,..20,..24,..28,..32,..36,..40,..44,..48$
0,...5,..10,..15,..20,..25,..30,..35,..40,..45,..50,..55,..60$
0,...6,..12,..18,..24,..30,..36,..42,..48,..54,..60,..66,..72$
0,...7,..14,..21,..28,..35,..42,..49,..56,..63,..70,..77,..84$
0,...8,..16,..24,..32,..40,..48,..56,..64,..72,..80,..88,..96$
0,...9,..18,..27,..36,..45,..54,..63,..72,..81,..90,..99,.108$
0,..10,..20,..30,..40,..50,..60,..70,..80,..90,.100,.110,.120$
0,..11,..22,..33,..44,..55,..66,..77,..88,..99,.110,.121,.132$
0,..12,..24,..36,..48,..60,..72,..84,..96,.108,.120,.132,.144$
julien@ubuntu:~/0x02$
Repo:
Repo:
Repo:
Repo:
Repo:
General
• What is debugging
• What are some methods of debugging manually
• How to read the error messages
Copyright - Plagiarism
• You are tasked to come up with solutions for the tasks below yourself to meet with the
above learning objectives.
• You will not be able to meet the objectives of this or any following project by copying and
pasting someone else’s work.
• You are not allowed to publish any content of this project.
• Any form of plagiarism is strictly forbidden and will result in removal from the program.
Requirements
General
• Allowed editors: vi, vim, emacs
• All your files will be compiled on Ubuntu 20.04 LTS using gcc, using the options -Wall -
Werror -Wextra -pedantic -std=gnu89
• All your files should end with a new line
• Your code should use the Betty style. It will be checked using betty-
style.pl and betty-doc.pl
• A README.md file at the root of the repo, containing a description of the repository
• A README.md file, at the root of the folder of this project (i.e. 0x03-debugging),
describing what this project is about
Quiz questions
Great! You've completed the quiz successfully! Keep going! (Show quiz)
Tasks
0. Multiple mains
mandatory
#include "main.h"
/**
* Return: 0
*/
int main(void)
int i;
i = 98;
positive_or_negative(i);
return (0);
carrie@ubuntu:/debugging$
#ifndef MAIN_H
#define MAIN_H
#include <stdio.h>
#endif /* MAIN_H */
carrie@ubuntu:/debugging$
carrie@ubuntu:/debugging$ ./a.out
98 is positive
carrie@ubuntu:/debugging$
Based on the main.c file above, create a file named 0-main.c. This file must test that the
function positive_or_negative() gives the correct output when given a case of 0.
You are not coding the solution / function, you’re just testing it! However, you can adapt your
function from 0x01. C - Variables, if, else, while - Task #0 to compile with this main file to test
locally.
• You only need to upload 0-main.c and main.h for this task. We will provide our
own positive_or_negative() function.
• You are not allowed to add or remove lines of code, you may change only one line in this
task.
carrie@ubuntu:/debugging$ ./0-main
0 is zero
carrie@ubuntu:/debugging$ wc -l 0-main.c
16 1-main.c
carrie@ubuntu:/debugging$
Repo:
• Don’t add or remove any lines of code, as we will be checking your line count. You are
only allowed to comment out existing code.
• You do not have to compile with -Wall -Werror -Wextra -pedantic for this task.
#include <stdio.h>
/**
*/
int main(void)
int i;
i = 0;
putchar(i);
return (0);
carrie@ubuntu:/debugging$
carrie@ubuntu:/debugging$ ./1-main
carrie@ubuntu:/debugging$ wc -l 1-main.c
24 1-main.c
carrie@ubuntu:/debugging$
Repo:
#include <stdio.h>
#include "main.h"
/**
* Return: 0
*/
int main(void)
int a, b, c;
int largest;
a = 972;
b = -98;
c = 0;
return (0);
carrie@ubuntu:/debugging$
#include "main.h"
/**
*/
int largest;
largest = a;
largest = b;
else
largest = c;
return (largest);
carrie@ubuntu:/debugging$
carrie@ubuntu:/debugging$ ./2-main
Repo:
#include <stdio.h>
#include "main.h"
/**
* main - takes a date and prints how many days are left in the year, taking
* Return: 0
*/
int main(void)
int month;
int day;
int year;
month = 4;
day = 01;
year = 1997;
printf("Date: %02d/%02d/%04d\n", month, day, year);
return (0);
carrie@ubuntu:/debugging$
#include "main.h"
/**
*/
switch (month)
case 2:
day = 31 + day;
break;
case 3:
day = 59 + day;
break;
case 4:
day = 90 + day;
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
break;
case 10:
break;
case 11:
break;
case 12:
break;
default:
break;
return (day);
carrie@ubuntu:/debugging$
carrie@ubuntu:/debugging$ cat 3-print_remaining_days.c
#include <stdio.h>
#include "main.h"
/**
* @year: year
* Return: void
*/
day++;
else
else
{
printf("Day of the year: %d\n", day);
carrie@ubuntu:/debugging$
carrie@ubuntu:/debugging$ ./3-main_a
Date: 04/01/1997
carrie@ubuntu:/debugging$
Output looks good for 04/01/1997! Let’s make a new main file 3-main_b.c to try a case that is a
leap year: 02/29/2000.
carrie@ubuntu:/debugging$ ./3-main_b
Date: 02/29/2000
carrie@ubuntu:/debugging$
Repo:
More Info
You do not have to understand the call by reference (address), stack, static variables, recursions
or arrays, yet.
Quiz questions
Great! You've completed the quiz successfully! Keep going! (Show quiz)
Tasks
0. isupper
mandatory
FYI: The standard library provides a similar function: isupper. Run man isupper to learn more.
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
char c;
c = 'A';
c = 'a';
return (0);
julien@ubuntu:~/0x04$ ./0-isuper
A: 1
a: 0
julien@ubuntu:~/0x04$
Repo:
FYI: The standard library provides a similar function: isdigit. Run man isdigit to learn more.
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
char c;
c = '0';
c = 'a';
return (0);
julien@ubuntu:~/0x04$ ./1-isdigit
0: 1
a: 0
julien@ubuntu:~/0x04$
Repo:
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
return (0);
julien@ubuntu:~/0x04$ ./2-mul
100352
-1646592
julien@ubuntu:~/0x04$
Repo:
#include "main.h"
/**
* Return: Always 0.
*/
int main(void)
print_numbers();
return (0);
0123456789$
julien@ubuntu:~/0x04$
Repo:
#include "main.h"
/**
* Return: Always 0.
*/
int main(void)
print_most_numbers();
return (0);
julien@ubuntu:~/0x04$ ./4-print_most_numbers
01356789
julien@ubuntu:~/0x04$
Repo:
#include "main.h"
/**
* Return: Always 0.
*/
int main(void)
more_numbers();
return (0);
julien@ubuntu:~/0x04$ ./5-more_numbers
01234567891011121314
01234567891011121314
01234567891011121314
01234567891011121314
01234567891011121314
01234567891011121314
01234567891011121314
01234567891011121314
01234567891011121314
01234567891011121314
julien@ubuntu:~/0x04
Repo:
#include "main.h"
/**
* Return: Always 0.
*/
int main(void)
print_line(0);
print_line(2);
print_line(10);
print_line(-4);
return (0);
__$
__________$
julien@ubuntu:~/0x04$
Repo:
#include "main.h"
/**
* Return: Always 0.
*/
int main(void)
print_diagonal(0);
print_diagonal(2);
print_diagonal(10);
print_diagonal(-4);
return (0);
\$
\$
\$
\$
\$
\$
\$
\$
\$
\$
\$
\$
julien@ubuntu:~/0x04$
Repo:
#include "main.h"
/**
* Return: Always 0.
*/
int main(void)
print_square(2);
print_square(10);
print_square(0);
return (0);
julien@ubuntu:~/0x04$ ./8-squares
##
##
##########
##########
##########
##########
##########
##########
##########
##########
##########
##########
julien@ubuntu:~/0x04$
Repo:
julien@ubuntu:~/0x04$ ./9-fizz_buzz
julien@ubuntu:~/0x04$
Repo:
#include "main.h"
/**
* Return: Always 0.
*/
int main(void)
print_triangle(2);
print_triangle(10);
print_triangle(1);
print_triangle(0);
return (0);
julien@ubuntu:~/0x04$ ./10-triangles
##
##
###
####
#####
######
#######
########
#########
##########
.#$
##$
.........#$
........##$
.......###$
......####$
.....#####$
....######$
...#######$
..########$
.#########$
##########$
#$
julien@ubuntu:~/0x04$
Repo:
Repo:
#include "main.h"
/**
* Return: Always 0.
*/
int main(void)
print_number(98);
_putchar('\n');
print_number(402);
_putchar('\n');
print_number(1024);
_putchar('\n');
print_number(0);
_putchar('\n');
print_number(-98);
_putchar('\n');
return (0);
julien@ubuntu:~/0x04$ ./101-print_numbers
98
402
1024
-98
julien@ubuntu:~/0x04$
Repo:
Learning Objectives
At the end of this project, you are expected to be able to explain to anyone, without the help of
Google:
General
• What are nested loops and how to use them
• What is a function and how do you use functions
• What is the difference between a declaration and a definition of a function
• What is a prototype
• Scope of variables
• What are the gcc flags -Wall -Werror -pedantic -Wextra -std=gnu89
• What are header files and how to to use them with #include
Copyright - Plagiarism
• You are tasked to come up with solutions for the tasks below yourself to meet with the
above learning objectives.
• You will not be able to meet the objectives of this or any following project by copying and
pasting someone else’s work.
• You are not allowed to publish any content of this project.
• Any form of plagiarism is strictly forbidden and will result in removal from the program.
Requirements
General
• Allowed editors: vi, vim, emacs
• All your files will be compiled on Ubuntu 20.04 LTS using gcc, using the options -Wall -
Werror -Wextra -pedantic -std=gnu89
• All your files should end with a new line
• A README.md file, at the root of the folder of the project is mandatory
• Your code should use the Betty style. It will be checked using betty-style.pl and betty-
doc.pl
• You are not allowed to use global variables
• No more than 5 functions per file
• You are not allowed to use the standard library. Any use of functions like printf, puts,
etc… is forbidden
• You are allowed to use _putchar
• You don’t have to push _putchar.c, we will use our file. If you do it won’t be taken into
account
• In the following examples, the main.c files are shown as examples. You can use them to
test your functions, but you don’t have to push them to your repo (if you do we won’t take
them into account). We will use our own main.c files at compilation. Our main.c files
might be different from the one shown in the examples
• The prototypes of all your functions and the prototype of the function _putchar should be
included in your header file called main.h
• Don’t forget to push your header file
More Info
You do not have to understand the call by reference (address), stack, static variables, recursions
or arrays, yet.
Quiz questions
Great! You've completed the quiz successfully! Keep going! (Show quiz)
Tasks
0. isupper
mandatory
FYI: The standard library provides a similar function: isupper. Run man isupper to learn more.
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
char c;
c = 'A';
c = 'a';
return (0);
julien@ubuntu:~/0x04$ ./0-isuper
A: 1
a: 0
julien@ubuntu:~/0x04$
Repo:
FYI: The standard library provides a similar function: isdigit. Run man isdigit to learn more.
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
char c;
c = '0';
c = 'a';
return (0);
julien@ubuntu:~/0x04$ ./1-isdigit
0: 1
a: 0
julien@ubuntu:~/0x04$
Repo:
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
return (0);
julien@ubuntu:~/0x04$ ./2-mul
100352
-1646592
julien@ubuntu:~/0x04$
Repo:
#include "main.h"
/**
* Return: Always 0.
*/
int main(void)
print_numbers();
return (0);
0123456789$
julien@ubuntu:~/0x04$
Repo:
#include "main.h"
/**
* Return: Always 0.
*/
int main(void)
print_most_numbers();
return (0);
julien@ubuntu:~/0x04$ ./4-print_most_numbers
01356789
julien@ubuntu:~/0x04$
Repo:
#include "main.h"
/**
* Return: Always 0.
*/
int main(void)
more_numbers();
return (0);
julien@ubuntu:~/0x04$ ./5-more_numbers
01234567891011121314
01234567891011121314
01234567891011121314
01234567891011121314
01234567891011121314
01234567891011121314
01234567891011121314
01234567891011121314
01234567891011121314
01234567891011121314
julien@ubuntu:~/0x04
Repo:
#include "main.h"
/**
* Return: Always 0.
*/
int main(void)
print_line(0);
print_line(2);
print_line(10);
print_line(-4);
return (0);
__$
__________$
julien@ubuntu:~/0x04$
Repo:
#include "main.h"
/**
* Return: Always 0.
*/
int main(void)
print_diagonal(0);
print_diagonal(2);
print_diagonal(10);
print_diagonal(-4);
return (0);
\$
\$
\$
\$
\$
\$
\$
\$
\$
\$
\$
\$
julien@ubuntu:~/0x04$
Repo:
• GitHub repository: alx-low_level_programming
• Directory: 0x04-more_functions_nested_loops
• File: 7-print_diagonal.c
#include "main.h"
/**
* Return: Always 0.
*/
int main(void)
print_square(2);
print_square(10);
print_square(0);
return (0);
julien@ubuntu:~/0x04$ ./8-squares
##
##
##########
##########
##########
##########
##########
##########
##########
##########
##########
##########
julien@ubuntu:~/0x04$
Repo:
julien@ubuntu:~/0x04$ ./9-fizz_buzz
julien@ubuntu:~/0x04$
Repo:
#include "main.h"
/**
* Return: Always 0.
*/
int main(void)
print_triangle(2);
print_triangle(10);
print_triangle(1);
print_triangle(0);
return (0);
julien@ubuntu:~/0x04$ ./10-triangles
##
#
##
###
####
#####
######
#######
########
#########
##########
.#$
##$
.........#$
........##$
.......###$
......####$
.....#####$
....######$
...#######$
..########$
.#########$
##########$
#$
julien@ubuntu:~/0x04$
Repo:
Repo:
#include "main.h"
/**
* Return: Always 0.
*/
int main(void)
print_number(98);
_putchar('\n');
print_number(402);
_putchar('\n');
print_number(1024);
_putchar('\n');
print_number(0);
_putchar('\n');
print_number(-98);
_putchar('\n');
return (0);
julien@ubuntu:~/0x04$ ./101-print_numbers
98
402
1024
-98
julien@ubuntu:~/0x04$
Repo:
• C - Arrays
• C - Pointers
• C - Strings
• Memory Layout
Learning Objectives
At the end of this project, you are expected to be able to explain to anyone, without the help of
Google:
General
• What are pointers and how to use them
• What are arrays and how to use them
• What are the differences between pointers and arrays
• How to use strings and how to manipulate them
• Scope of variables
Copyright - Plagiarism
• You are tasked to come up with solutions for the tasks below yourself to meet with the
above learning objectives.
• You will not be able to meet the objectives of this or any following project by copying and
pasting someone else’s work.
• You are not allowed to publish any content of this project.
• Any form of plagiarism is strictly forbidden and will result in removal from the program.
Requirements
General
• Allowed editors: vi, vim, emacs
• All your files will be compiled on Ubuntu 20.04 LTS using gcc, using the options -Wall -
Werror -Wextra -pedantic -std=gnu89
• All your files should end with a new line
• A README.md file, at the root of the folder of the project is mandatory
• Your code should use the Betty style. It will be checked using betty-style.pl and betty-
doc.pl
• You are not allowed to use global variables
• No more than 5 functions per file
• You are not allowed to use the standard library. Any use of functions like printf, puts,
etc… is forbidden
• You are allowed to use _putchar
• You don’t have to push _putchar.c, we will use our file. If you do it won’t be taken into
account
• In the following examples, the main.c files are shown as examples. You can use them to
test your functions, but you don’t have to push them to your repo (if you do we won’t take
them into account). We will use our own main.c files at compilation. Our main.c files
might be different from the one shown in the examples
• The prototypes of all your functions and the prototype of the function _putchar should be
included in your header file called main.h
• Don’t forget to push your header file
More Info
You do not need to learn about pointers to functions, pointers to pointers, multidimensional
arrays, arrays of structures, malloc and free - yet.
Quiz questions
Great! You've completed the quiz successfully! Keep going! (Show quiz)
Tasks
0. 98 Battery st.
mandatory
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
int n;
n = 402;
printf("n=%d\n", n);
reset_to_98(&n);
printf("n=%d\n", n);
return (0);
julien@ubuntu:~/0x05$ ./0-98
n=402
n=98
julien@ubuntu:~/0x05$
Repo:
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
{
int a;
int b;
a = 98;
b = 42;
swap_int(&a, &b);
return (0);
julien@ubuntu:~/0x05$ ./1-swap
a=98, b=42
a=42, b=98
julien@ubuntu:~/0x05$
Repo:
FYI: The standard library provides a similar function: strlen. Run man strlen to learn more.
#include "main.h"
#include <stdio.h>
/**
* main - check the code
* Return: Always 0.
*/
int main(void)
char *str;
int len;
len = _strlen(str);
printf("%d\n", len);
return (0);
julien@ubuntu:~/0x05$ ./2-strlen
16
julien@ubuntu:~/0x05$
Repo:
FYI: The standard library provides a similar function: puts. Run man puts to learn more.
#include "main.h"
/**
* Return: Always 0.
*/
int main(void)
char *str;
str = "I do not fear computers. I fear the lack of them - Isaac Asimov"
;
_puts(str);
return (0);
julien@ubuntu:~/0x05$ ./3-puts
julien@ubuntu:~/0x05$
Repo:
#include "main.h"
/**
* Return: Always 0.
*/
int main(void)
char *str;
str = "I do not fear computers. I fear the lack of them - Isaac Asimov"
;
print_rev(str);
return (0);
julien@ubuntu:~/0x05$ ./4-print_rev
julien@ubuntu:~/0x05$
Repo:
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
printf("%s\n", s);
rev_string(s);
printf("%s\n", s);
return (0);
julien@ubuntu:~/0x05$ ./5-rev_string
My School
loohcS yM
julien@ubuntu:~/0x05$
Repo:
#include "main.h"
/**
* Return: Always 0.
*/
int main(void)
char *str;
str = "0123456789";
puts2(str);
return (0);
julien@ubuntu:~/0x05$ ./6-puts2
02468
julien@ubuntu:~/0x05$
Repo:
#include "main.h"
/**
* Return: Always 0.
*/
int main(void)
char *str;
str = "0123456789";
puts_half(str);
return (0);
julien@ubuntu:~/0x05$ ./7-puts_half
56789
julien@ubuntu:~/0x05$
Repo:
#include "main.h"
/**
* Return: Always 0.
*/
int main(void)
int array[5];
array[0] = 98;
array[1] = 402;
array[2] = -198;
array[3] = 298;
array[4] = -1024;
print_array(array, 5);
return (0);
julien@ubuntu:~/0x05$ ./8-print_array
julien@ubuntu:~/0x05$
Repo:
Write a function that copies the string pointed to by src, including the terminating null byte (\0),
to the buffer pointed to by dest.
• Return value: the pointer to dest
FYI: The standard library provides a similar function: strcpy. Run man strcpy to learn more.
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
char s1[98];
char *ptr;
ptr = _strcpy(s1, "First, solve the problem. Then, write the code\n");
printf("%s", s1);
printf("%s", ptr);
return (0);
julien@ubuntu:~/0x05$ ./9-strcpy
julien@ubuntu:~/0x05$
Repo:
FYI: The standard library provides a similar function: atoi. Run man atoi to learn more.
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
int nb;
nb = _atoi("98");
printf("%d\n", nb);
nb = _atoi("-402");
printf("%d\n", nb);
nb = _atoi(" ------++++++-----+++++--98");
printf("%d\n", nb);
nb = _atoi("214748364");
printf("%d\n", nb);
nb = _atoi("0");
printf("%d\n", nb);
nb = _atoi("Suite 402");
printf("%d\n", nb);
printf("%d\n", nb);
printf("%d\n", nb);
return (0);
julien@ubuntu:~/0x05$ ./100-atoi
98
-402
-98
214748364
402
98
402
julien@ubuntu:~/0x05$
Repo:
Tada! Congrats
julien@ubuntu:~/0x05$
Repo:
General
• What are pointers and how to use them
• What are arrays and how to use them
• What are the differences between pointers and arrays
• How to use strings and how to manipulate them
• Scope of variables
Copyright - Plagiarism
• You are tasked to come up with solutions for the tasks below yourself to meet with the
above learning objectives.
• You will not be able to meet the objectives of this or any following project by copying and
pasting someone else’s work.
• You are not allowed to publish any content of this project.
• Any form of plagiarism is strictly forbidden and will result in removal from the program.
Requirements
General
• Allowed editors: vi, vim, emacs
• All your files will be compiled on Ubuntu 20.04 LTS using gcc, using the options -Wall -
Werror -Wextra -pedantic -std=gnu89
• All your files should end with a new line
• A README.md file, at the root of the folder of the project is mandatory
• Your code should use the Betty style. It will be checked using betty-style.pl and betty-
doc.pl
• You are not allowed to use global variables
• No more than 5 functions per file
• You are not allowed to use the standard library. Any use of functions like printf, puts,
etc… is forbidden
• You are allowed to use _putchar
• You don’t have to push _putchar.c, we will use our file. If you do it won’t be taken into
account
• In the following examples, the main.c files are shown as examples. You can use them to
test your functions, but you don’t have to push them to your repo (if you do we won’t take
them into account). We will use our own main.c files at compilation. Our main.c files
might be different from the one shown in the examples
• The prototypes of all your functions and the prototype of the function _putchar should be
included in your header file called main.h
• Don’t forget to push your header file
Quiz questions
Great! You've completed the quiz successfully! Keep going! (Show quiz)
Tasks
0. strcat
mandatory
FYI: The standard library provides a similar function: strcat. Run man strcat to learn more.
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
char *ptr;
printf("%s\n", s1);
printf("%s", s2);
printf("%s", s1);
printf("%s", s2);
printf("%s", ptr);
return (0);
julien@ubuntu:~/0x06$ ./0-strcat
Hello
World!
Hello World!
World!
Hello World!
julien@ubuntu:~/0x06$
Repo:
FYI: The standard library provides a similar function: strncat. Run man strncat to learn more.
#include "main.h"
#include <stdio.h>
/**
*
* Return: Always 0.
*/
int main(void)
char *ptr;
printf("%s\n", s1);
printf("%s", s2);
printf("%s\n", s1);
printf("%s", s2);
printf("%s\n", ptr);
printf("%s", s1);
printf("%s", s2);
printf("%s", ptr);
return (0);
julien@ubuntu:~/0x06$ ./1-strncat
Hello
World!
Hello W
World!
Hello W
Hello WWorld!
World!
Hello WWorld!
julien@ubuntu:~/0x06$
Repo:
• GitHub repository: alx-low_level_programming
• Directory: 0x06-pointers_arrays_strings
• File: 1-strncat.c
FYI: The standard library provides a similar function: strncpy. Run man strncpy to learn more.
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
char s1[98];
char *ptr;
int i;
s1[i] = '*';
s1[i] = '\0';
printf("%s\n", s1);
ptr = _strncpy(s1, "First, solve the problem. Then, write the code\n",
5);
printf("%s\n", s1);
printf("%s\n", ptr);
ptr = _strncpy(s1, "First, solve the problem. Then, write the code\n",
90);
printf("%s", s1);
printf("%s", ptr);
if (i % 10)
printf(" ");
printf("\n");
printf("0x%02x", s1[i]);
printf("\n");
return (0);
julien@ubuntu:~/0x06$ ./2-strncpy
***************************************************************************
**********************
First**********************************************************************
**********************
First**********************************************************************
**********************
0x46 0x69 0x72 0x73 0x74 0x2c 0x20 0x73 0x6f 0x6c
0x76 0x65 0x20 0x74 0x68 0x65 0x20 0x70 0x72 0x6f
0x62 0x6c 0x65 0x6d 0x2e 0x20 0x54 0x68 0x65 0x6e
0x2c 0x20 0x77 0x72 0x69 0x74 0x65 0x20 0x74 0x68
0x65 0x20 0x63 0x6f 0x64 0x65 0x0a 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
julien@ubuntu:~/0x06$
Repo:
FYI: The standard library provides a similar function: strcmp. Run man strcmp to learn more.
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
return (0);
julien@ubuntu:~/0x06$ ./3-strcmp
-15
15
julien@ubuntu:~/0x06$
Repo:
#include "main.h"
#include <stdio.h>
/**
*
* Return: nothing.
*/
int i;
i = 0;
while (i < n)
if (i != 0)
printf(", ");
printf("%d", a[i]);
i++;
printf("\n");
/**
* Return: Always 0.
*/
int main(void)
return (0);
}
julien@ubuntu:~/0x06$ gcc -Wall -pedantic -Werror -Wextra -std=gnu89 4-main
.c 4-rev_array.c -o 4-rev_array
julien@ubuntu:~/0x06$ ./4-rev_array
julien@ubuntu:~/0x06$
Repo:
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
char *ptr;
ptr = string_toupper(str);
printf("%s", ptr);
printf("%s", str);
return (0);
julien@ubuntu:~/0x06$ ./5-string_toupper
LOOK UP!
LOOK UP!
julien@ubuntu:~/0x06$
Repo:
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
char str[] = "Expect the best. Prepare for the worst. Capitalize on wha
t comes.\nhello world! hello-world 0123456hello world\thello world.hello wo
rld\n";
char *ptr;
ptr = cap_string(str);
printf("%s", ptr);
printf("%s", str);
return (0);
julien@ubuntu:~/0x06$ ./6-cap
Expect The Best. Prepare For The Worst. Capitalize On What Comes.
Expect The Best. Prepare For The Worst. Capitalize On What Comes.
julien@ubuntu:~/0x06$
Repo:
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
char s[] = "Expect the best. Prepare for the worst. Capitalize on what
comes.\n";
char *p;
p = leet(s);
printf("%s", p);
printf("%s", s);
return (0);
julien@ubuntu:~/0x06$ ./7-1337
3xp3c7 7h3 b3s7. Pr3p4r3 f0r 7h3 w0rs7. C4pi741iz3 0n wh47 c0m3s.
3xp3c7 7h3 b3s7. Pr3p4r3 f0r 7h3 w0rs7. C4pi741iz3 0n wh47 c0m3s.
julien@ubuntu:~/0x06$
Repo:
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
char *p;
p = rot13(s);
printf("%s", p);
printf("------------------------------------\n");
printf("%s", s);
printf("------------------------------------\n");
p = rot13(s);
printf("%s", p);
printf("------------------------------------\n");
printf("%s", s);
printf("------------------------------------\n");
p = rot13(s);
printf("%s", p);
printf("------------------------------------\n");
printf("%s", s);
return (0);
julien@ubuntu:~/0x06$ ./100-rot13
EBG13 ("ebgngr ol 13 cynprf", fbzrgvzrf ulcurangrq EBG-13) vf n fvzcyr yrgg
re fhofgvghgvba pvcure.
------------------------------------
------------------------------------
------------------------------------
------------------------------------
------------------------------------
julien@ubuntu:~/0x06$
Repo:
#include "main.h"
/**
* main - check the code
* Return: Always 0.
*/
int main(void)
print_number(98);
_putchar('\n');
print_number(402);
_putchar('\n');
print_number(1024);
_putchar('\n');
print_number(0);
_putchar('\n');
print_number(-98);
_putchar('\n');
return (0);
julien@ubuntu:~/0x06$ ./101-print_numbers
98
402
1024
-98
julien@ubuntu:~/0x06$
Repo:
Add one line to this code, so that the program prints a[2] = 98, followed by a new line.
• You are not allowed to use the variable a in your new line of code
• You are not allowed to modify the variable p
• You can only write one statement
• You are not allowed to use ,
• You are not allowed to code anything else than the line of expected line of code at the
expected line
• Your code should be written at line 19, before the ;
• Do not remove anything from the initial code (not even the comments)
• and don’t change anything but the line of code you are adding (don’t change the spaces
to tabs!)
• You are allowed to use the standard library
Repo:
• Prototype: char *infinite_add(char *n1, char *n2, char *r, int size_r);
• Where n1 and n2 are the two numbers
• r is the buffer that the function will use to store the result
• size_r is the buffer size
• The function returns a pointer to the result
• You can assume that you will always get positive numbers, or 0
• You can assume that there will be only digits in the strings n1 and n2
• n1 and n2 will never be empty
• If the result can not be stored in r the function must return 0
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
char *n = "12345678924345743678235745756784776857856456858768767745
86734734563456453743756756784458";
char *m = "90347906634706972346829145693462596349586932465973246597
62347956349265983465962349569346";
char r[100];
char r2[10];
char r3[11];
char *res;
if (res == 0)
printf("Error\n");
else
n = "1234567890";
m = "1";
if (res == 0)
printf("Error\n");
else
}
n = "999999999";
m = "1";
if (res == 0)
printf("Error\n");
else
if (res == 0)
printf("Error\n");
else
return (0);
julien@ubuntu:~/0x06$ ./103-add
123456789243457436782357457567847768578564568587687677458673473456345645374
3756756784458 + 90347906634706972346829145693462596349586932465973246597623
47956349265983465962349569346 = 1026935855590527160250648914502473732074433
8932474201434349082690912722437209719106353804
Error
Error
999999999 + 1 = 1000000000
julien@ubuntu:~/0x06$
Repo:
• GitHub repository: alx-low_level_programming
• Directory: 0x06-pointers_arrays_strings
• File: 103-infinite_add.c
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
printf("%s\n", buffer);
printf("---------------------------------\n");
print_buffer(buffer, sizeof(buffer));
return (0);
julien@ubuntu:~/0x06$ ./104-buffer
This is a string!
---------------------------------
julien@ubuntu:~/0x06$
Repo:
Resources
Read or watch:
• C - Pointer to Pointer
• C – Pointer to Pointer with example
• Multi-dimensional Arrays in C
• Two dimensional (2D) arrays in C programming with example
Learning Objectives
At the end of this project, you are expected to be able to explain to anyone, without the help of
Google:
General
• What are pointers to pointers and how to use them
• What are multidimensional arrays and how to use them
• What are the most common C standard library functions to manipulate strings
Copyright - Plagiarism
• You are tasked to come up with solutions for the tasks below yourself to meet with the
above learning objectives.
• You will not be able to meet the objectives of this or any following project by copying and
pasting someone else’s work.
• You are not allowed to publish any content of this project.
• Any form of plagiarism is strictly forbidden and will result in removal from the program.
Requirements
General
• Allowed editors: vi, vim, emacs
• All your files will be compiled on Ubuntu 20.04 LTS using gcc, using the options -Wall -
Werror -Wextra -pedantic -std=gnu89
• All your files should end with a new line
• A README.md file, at the root of the folder of the project is mandatory
• Your code should use the Betty style. It will be checked using betty-style.pl and betty-
doc.pl
• You are not allowed to use global variables
• No more than 5 functions per file
• You are not allowed to use the standard library. Any use of functions like printf, puts,
etc… is forbidden
• You are allowed to use _putchar
• You don’t have to push _putchar.c, we will use our file. If you do it won’t be taken into
account
• In the following examples, the main.c files are shown as examples. You can use them to
test your functions, but you don’t have to push them to your repo (if you do we won’t take
them into account). We will use our own main.c files at compilation. Our main.c files
might be different from the one shown in the examples
• The prototypes of all your functions and the prototype of the function _putchar should be
included in your header file called main.h
• Don’t forget to push your header file
More Info
You do not need to learn about pointers to functions, arrays of structures, malloc and free - yet.
Quiz questions
Great! You've completed the quiz successfully! Keep going! (Show quiz)
Tasks
0. memset
mandatory
Score: 100.0% (Checks completed: 100.0%)
Write a function that fills memory with a constant byte.
FYI: The standard library provides a similar function: memset. Run man memset to learn more.
#include "main.h"
#include <stdio.h>
/**
* Return: Nothing.
*/
unsigned int i;
i = 0;
if (i % 10)
printf(" ");
printf("\n");
}
printf("0x%02x", buffer[i]);
i++;
printf("\n");
/**
* Return: Always 0.
*/
int main(void)
simple_print_buffer(buffer, 98);
printf("-------------------------------------------------\n");
simple_print_buffer(buffer, 98);
return (0);
julien@ubuntu:~/0x07$ ./0-memset
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
julien@ubuntu:~/0x07$
Repo:
FYI: The standard library provides a similar function: memcpy. Run man memcpy to learn more.
#include "main.h"
#include <stdio.h>
/**
*
* Return: Nothing.
*/
unsigned int i;
i = 0;
if (i % 10)
printf(" ");
printf("\n");
printf("0x%02x", buffer[i]);
i++;
printf("\n");
/**
* Return: Always 0.
*/
int main(void)
printf("-------------------------------------------------\n");
simple_print_buffer(buffer, 98);
return (0);
julien@ubuntu:~/0x07$ ./1-memcpy
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
-------------------------------------------------
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x01 0x02 0x03 0x04 0x05 0x07 0x07 0x08 0x09 0x0a
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
julien@ubuntu:~/0x07$
Repo:
FYI: The standard library provides a similar function: strchr. Run man strchr to learn more.
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
char *s = "hello";
char *f;
f = _strchr(s, 'l');
if (f != NULL)
printf("%s\n", f);
return (0);
llo
julien@ubuntu:~/0x07$
Repo:
FYI: The standard library provides a similar function: strspn. Run man strspn to learn more.
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
char *f = "oleh";
unsigned int n;
n = _strspn(s, f);
printf("%u\n", n);
return (0);
}
julien@ubuntu:~/0x07$ ./3-strspn
julien@ubuntu:~/0x07$
Repo:
FYI: The standard library provides a similar function: strpbrk. Run man strpbrk to learn more.
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
char *f = "world";
char *t;
t = _strpbrk(s, f);
printf("%s\n", t);
return (0);
julien@ubuntu:~/0x07$ ./4-strpbrk
llo, world
julien@ubuntu:~/0x07$
Repo:
FYI: The standard library provides a similar function: strstr. Run man strstr to learn more.
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
{
char *f = "world";
char *t;
t = _strstr(s, f);
printf("%s\n", t);
return (0);
julien@ubuntu:~/0x07$ ./5-strstr
world
julien@ubuntu:~/0x07$
Repo:
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
char board[8][8] = {
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
};
print_chessboard(board);
return (0);
julien@ubuntu:~/0x07$ ./7-print_chessboard
rkbqkbkr
pppppppp
PPPPPPPP
RKBQKBKR
julien@ubuntu:~/0x07$
Repo:
Note that in the following example we are casting an int[][] into an int*. This is not something
you should do. The goal here is to make sure you understand how an array of array is stored in
memory.
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
int c3[3][3] = {
{0, 1, 5},
};
int c5[5][5] = {
};
julien@ubuntu:~/0x07$ ./8-print_diagsums
113, 1016
1214556093, 1137318
julien@ubuntu:~/0x07$
Repo:
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
return (0);
julien@ubuntu:~/0x07$ ./100-set_string
julien@ubuntu:~/0x07$
Repo:
• Your file should contain the exact password, no new line, no extra space
• ltrace, ldd, gdb and objdump can help
• You may need to install the openssl library to run the crakme2 program: sudo apt
install libssl-dev
• Edit the source list sudo nano /etc/apt/sources.list to add the following line: deb
http://security.ubuntu.com/ubuntu xenial-security main Then sudo apt
update and sudo apt install libssl1.0.0
Repo:
Learning Objectives
At the end of this project, you are expected to be able to explain to anyone, without the help of
Google:
General
• What is recursion
• How to implement recursion
• In what situations you should implement recursion
• In what situations you shouldn’t implement recursion
Copyright - Plagiarism
• You are tasked to come up with solutions for the tasks below yourself to meet with the
above learning objectives.
• You will not be able to meet the objectives of this or any following project by copying and
pasting someone else’s work.
• You are not allowed to publish any content of this project.
• Any form of plagiarism is strictly forbidden and will result in removal from the program.
Requirements
General
• Allowed editors: vi, vim, emacs
• All your files will be compiled on Ubuntu 20.04 LTS using gcc, using the options -Wall -
Werror -Wextra -pedantic -std=gnu89
• All your files should end with a new line
• A README.md file, at the root of the folder of the project is mandatory
• Your code should use the Betty style. It will be checked using betty-style.pl and betty-
doc.pl
• You are not allowed to use global variables
• No more than 5 functions per file
• You are not allowed to use the standard library. Any use of functions like printf, puts,
etc… is forbidden
• You are allowed to use _putchar
• You don’t have to push _putchar.c, we will use our file. If you do it won’t be taken into
account
• In the following examples, the main.c files are shown as examples. You can use them to
test your functions, but you don’t have to push them to your repo (if you do we won’t take
them into account). We will use our own main.c files at compilation. Our main.c files
might be different from the one shown in the examples
• The prototypes of all your functions and the prototype of the function _putchar should be
included in your header file called main.h
• Don’t forget to push your header file
• You are not allowed to use any kind of loops
• You are not allowed to use static variables
Quiz questions
Great! You've completed the quiz successfully! Keep going! (Show quiz)
Tasks
0. She locked away a secret, deep inside herself, something she once knew to be true...
but chose to forget
mandatory
FYI: The standard library provides a similar function: puts. Run man puts to learn more.
#include "main.h"
/**
* Return: Always 0.
*/
int main(void)
return (0);
julien@ubuntu:~/0x08. Recursion$
Repo:
#include "main.h"
/**
* Return: Always 0.
*/
int main(void)
_print_rev_recursion("\nColton Walker");
return (0);
reklaW notloC
julien@ubuntu:~/0x08. Recursion$
Repo:
• GitHub repository: alx-low_level_programming
• Directory: 0x08-recursion
• File: 1-print_rev_recursion.c
FYI: The standard library provides a similar function: strlen. Run man strlen to learn more.
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
int n;
n = _strlen_recursion("Corbin Coleman");
printf("%d\n", n);
return (0);
14
julien@ubuntu:~/0x08. Recursion$
Repo:
• GitHub repository: alx-low_level_programming
• Directory: 0x08-recursion
• File: 2-strlen_recursion.c
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
int r;
r = factorial(1);
printf("%d\n", r);
r = factorial(5);
printf("%d\n", r);
r = factorial(10);
printf("%d\n", r);
r = factorial(-1024);
printf("%d\n", r);
return (0);
}
julien@ubuntu:~/0x08. Recursion$ gcc -Wall -pedantic -Werror -Wextra -std=g
nu89 3-main.c 3-factorial.c -o 3-factorial
120
3628800
-1
julien@ubuntu:~/0x08. Recursion$
Repo:
FYI: The standard library provides a different function: pow. Run man pow to learn more.
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
int r;
r = _pow_recursion(1, 10);
printf("%d\n", r);
r = _pow_recursion(1024, 0);
printf("%d\n", r);
r = _pow_recursion(2, 16);
printf("%d\n", r);
r = _pow_recursion(5, 2);
printf("%d\n", r);
r = _pow_recursion(5, -2);
printf("%d\n", r);
r = _pow_recursion(-5, 3);
printf("%d\n", r);
return (0);
65536
25
-1
-125
julien@ubuntu:~/0x08. Recursion$
Repo:
FYI: The standard library provides a different function: sqrt. Run man sqrt to learn more.
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
int r;
r = _sqrt_recursion(1);
printf("%d\n", r);
r = _sqrt_recursion(1024);
printf("%d\n", r);
r = _sqrt_recursion(16);
printf("%d\n", r);
r = _sqrt_recursion(17);
printf("%d\n", r);
r = _sqrt_recursion(25);
printf("%d\n", r);
r = _sqrt_recursion(-1);
printf("%d\n", r);
return (0);
1
32
-1
-1
julien@ubuntu:~/0x08. Recursion$
Repo:
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
int r;
r = is_prime_number(1);
printf("%d\n", r);
r = is_prime_number(1024);
printf("%d\n", r);
r = is_prime_number(16);
printf("%d\n", r);
r = is_prime_number(17);
printf("%d\n", r);
r = is_prime_number(25);
printf("%d\n", r);
r = is_prime_number(-1);
printf("%d\n", r);
r = is_prime_number(113);
printf("%d\n", r);
r = is_prime_number(7919);
printf("%d\n", r);
return (0);
julien@ubuntu:~/0x08. Recursion$
Repo:
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
int r;
r = is_palindrome("level");
printf("%d\n", r);
r = is_palindrome("redder");
printf("%d\n", r);
r = is_palindrome("test");
printf("%d\n", r);
r = is_palindrome("step on no pets");
printf("%d\n", r);
return (0);
0
1
julien@ubuntu:~/0x08. Recursion$
Repo:
#include "main.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
int r;
r = wildcmp("main.c", "*.c");
printf("%d\n", r);
r = wildcmp("main.c", "m*a*i*n*.*c*");
printf("%d\n", r);
r = wildcmp("main.c", "main.c");
printf("%d\n", r);
r = wildcmp("main.c", "m*c");
printf("%d\n", r);
r = wildcmp("main.c", "ma********************************c");
printf("%d\n", r);
r = wildcmp("main.c", "*");
printf("%d\n", r);
r = wildcmp("main.c", "***");
printf("%d\n", r);
r = wildcmp("main.c", "m.*c");
printf("%d\n", r);
r = wildcmp("main.c", "**.*c");
printf("%d\n", r);
r = wildcmp("main-main.c", "ma*in.c");
printf("%d\n", r);
r = wildcmp("main", "main*d");
printf("%d\n", r);
r = wildcmp("abc", "*b");
printf("%d\n", r);
return (0);
0
0
julien@ubuntu:~/0x08. Recursion$
Repo:
• C static libraries
Resources
Read or watch:
man or help:
• ar
• ranlib
• nm
Learning Objectives
At the end of this project, you are expected to be able to explain to anyone, without the help of
Google:
General
• What is a static library, how does it work, how to create one, and how to use it
• Basic usage of ar, ranlib, nm
Copyright - Plagiarism
• You are tasked to come up with solutions for the tasks below yourself to meet with the
above learning objectives.
• You will not be able to meet the objectives of this or any following project by copying and
pasting someone else’s work.
• You are not allowed to publish any content of this project.
• Any form of plagiarism is strictly forbidden and will result in removal from the program.
Requirements
C
• Allowed editors: vi, vim, emacs
• All your files will be compiled on Ubuntu 20.04 LTS using gcc, using the options -Wall -
Werror -Wextra -pedantic -std=gnu89
• All your files should end with a new line
• A README.md file, at the root of the folder of the project is mandatory
• Your code should use the Betty style. It will be checked using betty-style.pl and betty-
doc.pl
• You are not allowed to use global variables
• No more than 5 functions per file
• You are not allowed to use the standard library. Any use of functions like printf, puts,
etc… is forbidden
• You are allowed to use _putchar
• You don’t have to push _putchar.c, we will use our file. If you do it won’t be taken into
account
• In the following examples, the main.c files are shown as examples. You can use them to
test your functions, but you don’t have to push them to your repo (if you do we won’t take
them into account). We will use our own main.c files at compilation. Our main.c files
might be different from the one shown in the examples
• The prototypes of all your functions and the prototype of the function _putchar should be
included in your header file called main.h
• Don’t forget to push your header file
Bash
• Allowed editors: vi, vim, emacs
• All your scripts will be tested on Ubuntu 20.04 LTS
• All your files should end with a new line (why?)
• The first line of all your files should be exactly #!/bin/bash
• A README.md file, at the root of the folder of the project, describing what each script is
doing
• All your files must be executable
More Info
You do not need to learn about dynamic libraries, yet.
Quiz questions
Great! You've completed the quiz successfully! Keep going! (Show quiz)
Tasks
0. A library is not a luxury but one of the necessities of life
mandatory
If you haven’t coded all of the above functions create empty ones with the right prototype.
Don’t forget to push your main.h file to your repository. It should at least contain all the
prototypes of the above functions.
0-isupper.o
0-memset.o
0-strcat.o
1-isdigit.o
1-memcpy.o
1-strncat.o
100-atoi.o
2-strchr.o
2-strlen.o
2-strncpy.o
3-islower.o
3-puts.o
3-strcmp.o
3-strspn.o
4-isalpha.o
4-strpbrk.o
5-strstr.o
6-abs.o
9-strcpy.o
_putchar.o
0-isupper.o:
0000000000000000 T _isupper
0-memset.o:
0000000000000000 T _memset
0-strcat.o:
0000000000000000 T _strcat
1-isdigit.o:
0000000000000000 T _isdigit
1-memcpy.o:
0000000000000000 T _memcpy
1-strncat.o:
0000000000000000 T _strncat
100-atoi.o:
0000000000000000 T _atoi
2-strchr.o:
0000000000000000 T _strchr
2-strlen.o:
0000000000000000 T _strlen
2-strncpy.o:
0000000000000000 T _strncpy
3-islower.o:
0000000000000000 T _islower
3-puts.o:
U _putchar
0000000000000000 T _puts
3-strcmp.o:
0000000000000000 T _strcmp
3-strspn.o:
0000000000000000 T _strspn
4-isalpha.o:
0000000000000000 T _isalpha
4-strpbrk.o:
0000000000000000 T _strpbrk
5-strstr.o:
0000000000000000 T _strstr
6-abs.o:
0000000000000000 T _abs
9-strcpy.o:
0000000000000000 T _strcpy
_putchar.o:
0000000000000000 T _putchar
U write
#include "main.h"
int main(void)
_puts("\"At the end of the day, my goal was to be the best hacker\"\n\t
- Kevin Mitnick");
return (0);
"At the end of the day, my goal was to be the best hacker"
- Kevin Mitnick
Repo:
liball.a
0-isupper.o
0-memset.o
0-strcat.o
100-atoi.o
1-isdigit.o
1-memcpy.o
1-strncat.o
2-strchr.o
2-strlen.o
2-strncpy.o
3-islower.o
3-puts.o
3-strcmp.o
3-strspn.o
4-isalpha.o
4-strpbrk.o
5-strstr.o
6-abs.o
9-strcpy.o
_putchar.o
Repo:
• Arguments to main
• argc and argv
• What does argc and argv mean?
• how to compile with unused variables
Learning Objectives
At the end of this project, you are expected to be able to explain to anyone, without the help of
Google:
General
• How to use arguments passed to your program
• What are two prototypes of main that you know of, and in which case do you use one or
the other
• How to use __attribute__((unused)) or (void) to compile functions with unused
variables or parameters
Copyright - Plagiarism
• You are tasked to come up with solutions for the tasks below yourself to meet with the
above learning objectives.
• You will not be able to meet the objectives of this or any following project by copying and
pasting someone else’s work.
• You are not allowed to publish any content of this project.
• Any form of plagiarism is strictly forbidden and will result in removal from the program.
Requirements
General
• Allowed editors: vi, vim, emacs
• All your files will be compiled on Ubuntu 20.04 LTS using gcc, using the options -Wall -
Werror -Wextra -pedantic -std=gnu89
• All your files should end with a new line
• A README.md file, at the root of the folder of the project is mandatory
• Your code should use the Betty style. It will be checked using betty-style.pl and betty-
doc.pl
• You are not allowed to use global variables
• No more than 5 functions per file
• The prototypes of all your functions and the prototype of the function _putchar should be
included in your header file called main.h
• Don’t forget to push your header file
• You are allowed to use the standard library
Quiz questions
Great! You've completed the quiz successfully! Keep going! (Show quiz)
Tasks
0. It ain't what they call you, it's what you answer to
mandatory
• If you rename the program, it will print the new name, without having to compile it again
• You should not remove the path before the name of the program
./mynameis
./mynewnameis
Repo:
0
julien@ubuntu:~/0x0A. argc, argv$ ./nargs hello
Repo:
./args
julien@ubuntu:~/0x0A. argc, argv$ ./args You can do anything, but not every
thing.
./args
You
can
do
anything,
but
not
everything.
• Your program should print the result of the multiplication, followed by a new line
• You can assume that the two numbers and result of the multiplication can be stored in an
integer
• If the program does not receive two arguments, your program should print Error,
followed by a new line, and return 1
-6
795108790
Error
Repo:
1111
Error
Repo:
Error
Repo:
man or help:
• malloc
• free
Learning Objectives
At the end of this project, you are expected to be able to explain to anyone, without the help of
Google:
General
• What is the difference between automatic and dynamic allocation
• What is malloc and free and how to use them
• Why and when use malloc
• How to use valgrind to check for memory leak
Copyright - Plagiarism
• You are tasked to come up with solutions for the tasks below yourself to meet with the
above learning objectives.
• You will not be able to meet the objectives of this or any following project by copying and
pasting someone else’s work.
• You are not allowed to publish any content of this project.
• Any form of plagiarism is strictly forbidden and will result in removal from the program.
Requirements
General
• Allowed editors: vi, vim, emacs
• All your files will be compiled on Ubuntu 20.04 LTS using gcc, using the options -Wall -
Werror -Wextra -pedantic -std=gnu89
• All your files should end with a new line
• A README.md file, at the root of the folder of the project is mandatory
• Your code should use the Betty style. It will be checked using betty-style.pl and betty-
doc.pl
• You are not allowed to use global variables
• No more than 5 functions per file
• The only C standard library functions allowed are malloc and free. Any use of functions
like printf, puts, calloc, realloc etc… is forbidden
• You are allowed to use _putchar
• You don’t have to push _putchar.c, we will use our file. If you do it won’t be taken into
account
• In the following examples, the main.c files are shown as examples. You can use them to
test your functions, but you don’t have to push them to your repo (if you do we won’t take
them into account). We will use our own main.c files at compilation. Our main.c files
might be different from the one shown in the examples
• The prototypes of all your functions and the prototype of the function _putchar should be
included in your header file called main.h
• Don’t forget to push your header file
More Info
You do not have to learn about calloc and realloc.
Quiz questions
Great! You've completed the quiz successfully! Keep going! (Show quiz)
Tasks
0. Float like a butterfly, sting like a bee
mandatory
#include "main.h"
#include <stdio.h>
#include <stdlib.h>
/**
* Return: Nothing.
*/
void simple_print_buffer(char *buffer, unsigned int size)
unsigned int i;
i = 0;
if (i % 10)
printf(" ");
printf("\n");
printf("0x%02x", buffer[i]);
i++;
printf("\n");
/**
* Return: Always 0.
*/
int main(void)
char *buffer;
if (buffer == NULL)
{
printf("failed to allocate memory\n");
return (1);
simple_print_buffer(buffer, 98);
free(buffer);
return (0);
0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48
0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48
0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48
0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48
0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48
0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48
0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48
0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48
0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48
Repo:
FYI: The standard library provides a similar function: strdup. Run man strdup to learn more.
#include "main.h"
#include <stdio.h>
#include <stdlib.h>
/**
* Return: Always 0.
*/
int main(void)
char *s;
s = _strdup("ALX SE");
if (s == NULL)
return (1);
printf("%s\n", s);
free(s);
return (0);
ALX SE
Repo:
• GitHub repository: alx-low_level_programming
• Directory: 0x0B-malloc_free
• File: 1-strdup.c
#include "main.h"
#include <stdio.h>
#include <stdlib.h>
/**
* Return: Always 0.
*/
int main(void)
char *s;
if (s == NULL)
printf("failed\n");
return (1);
printf("%s\n", s);
free(s);
return (0);
julien@ubuntu:~/c/curriculum_by_julien/holbertonschool-low_level_programmin
g/0x0a. malloc, free$ ./c | cat -e
Betty Holberton$
julien@ubuntu:~/c/curriculum_by_julien/holbertonschool-low_level_programmin
g/0x0a. malloc, free$
Repo:
#include "main.h"
#include <stdio.h>
#include <stdlib.h>
/**
* Return: Nothing.
*/
void print_grid(int **grid, int width, int height)
int w;
int h;
h = 0;
w = 0;
w++;
printf("\n");
h++;
/**
* Return: Always 0.
*/
int main(void)
int **grid;
if (grid == NULL)
return (1);
}
print_grid(grid, 6, 4);
printf("\n");
grid[0][3] = 98;
grid[3][4] = 402;
print_grid(grid, 6, 4);
return (0);
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 98 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 402 0
Repo:
#include "main.h"
#include <stdio.h>
#include <stdlib.h>
/**
* Return: Nothing.
*/
int w;
int h;
h = 0;
w = 0;
w++;
printf("\n");
h++;
/**
*
* Return: Always 0.
*/
int main(void)
int **grid;
if (grid == NULL)
return (1);
print_grid(grid, 6, 4);
printf("\n");
grid[0][3] = 98;
grid[3][4] = 402;
print_grid(grid, 6, 4);
free_grid(grid, 4);
return (0);
==5013== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==5013== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==5013==
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 98 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 402 0
==5013==
==5013==
==5013==
Repo:
#include "main.h"
#include <stdio.h>
#include <stdlib.h>
/**
* Return: Always 0.
*/
char *s;
s = argstostr(ac, av);
if (s == NULL)
return (1);
printf("%s", s);
free(s);
return (0);
./args
will
show you
how
great
am
Repo:
#include "main.h"
#include <stdio.h>
#include <stdlib.h>
/**
* Return: nothing
*/
int i;
printf("%s\n", tab[i]);
/**
*/
int main(void)
{
char **tab;
if (tab == NULL)
printf("Failed\n");
return (1);
print_tab(tab);
return (0);
ALX$
School$
#cisfun$
Repo:
Resources
Read or watch:
man or help:
• malloc
• free
Learning Objectives
At the end of this project, you are expected to be able to explain to anyone, without the help of
Google:
General
• What is the difference between automatic and dynamic allocation
• What is malloc and free and how to use them
• Why and when use malloc
• How to use valgrind to check for memory leak
Copyright - Plagiarism
• You are tasked to come up with solutions for the tasks below yourself to meet with the
above learning objectives.
• You will not be able to meet the objectives of this or any following project by copying and
pasting someone else’s work.
• You are not allowed to publish any content of this project.
• Any form of plagiarism is strictly forbidden and will result in removal from the program.
Requirements
General
• Allowed editors: vi, vim, emacs
• All your files will be compiled on Ubuntu 20.04 LTS using gcc, using the options -Wall -
Werror -Wextra -pedantic -std=gnu89
• All your files should end with a new line
• A README.md file, at the root of the folder of the project is mandatory
• Your code should use the Betty style. It will be checked using betty-style.pl and betty-
doc.pl
• You are not allowed to use global variables
• No more than 5 functions per file
• The only C standard library functions allowed are malloc and free. Any use of functions
like printf, puts, calloc, realloc etc… is forbidden
• You are allowed to use _putchar
• You don’t have to push _putchar.c, we will use our file. If you do it won’t be taken into
account
• In the following examples, the main.c files are shown as examples. You can use them to
test your functions, but you don’t have to push them to your repo (if you do we won’t take
them into account). We will use our own main.c files at compilation. Our main.c files
might be different from the one shown in the examples
• The prototypes of all your functions and the prototype of the function _putchar should be
included in your header file called main.h
• Don’t forget to push your header file
More Info
You do not have to learn about calloc and realloc.
Quiz questions
Great! You've completed the quiz successfully! Keep going! (Show quiz)
Tasks
0. Float like a butterfly, sting like a bee
mandatory
#include "main.h"
#include <stdio.h>
#include <stdlib.h>
/**
* Return: Nothing.
*/
unsigned int i;
i = 0;
if (i % 10)
printf(" ");
printf("\n");
printf("0x%02x", buffer[i]);
i++;
printf("\n");
/**
* Return: Always 0.
*/
int main(void)
char *buffer;
buffer = create_array(98, 'H');
if (buffer == NULL)
return (1);
simple_print_buffer(buffer, 98);
free(buffer);
return (0);
0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48
0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48
0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48
0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48
0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48
0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48
0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48
0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48
0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48 0x48
Repo:
FYI: The standard library provides a similar function: strdup. Run man strdup to learn more.
#include "main.h"
#include <stdio.h>
#include <stdlib.h>
/**
* Return: Always 0.
*/
int main(void)
char *s;
s = _strdup("ALX SE");
if (s == NULL)
return (1);
printf("%s\n", s);
free(s);
return (0);
Repo:
#include "main.h"
#include <stdio.h>
#include <stdlib.h>
/**
* Return: Always 0.
*/
int main(void)
char *s;
if (s == NULL)
printf("failed\n");
return (1);
printf("%s\n", s);
free(s);
return (0);
julien@ubuntu:~/c/curriculum_by_julien/holbertonschool-low_level_programmin
g/0x0a. malloc, free$ ./c | cat -e
Betty Holberton$
julien@ubuntu:~/c/curriculum_by_julien/holbertonschool-low_level_programmin
g/0x0a. malloc, free$
Repo:
#include "main.h"
#include <stdio.h>
#include <stdlib.h>
/**
* Return: Nothing.
*/
int w;
int h;
h = 0;
w = 0;
w++;
printf("\n");
h++;
/**
* Return: Always 0.
*/
int main(void)
int **grid;
return (1);
print_grid(grid, 6, 4);
printf("\n");
grid[0][3] = 98;
grid[3][4] = 402;
print_grid(grid, 6, 4);
return (0);
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 98 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 402 0
Repo:
#include "main.h"
#include <stdio.h>
#include <stdlib.h>
/**
* Return: Nothing.
*/
int w;
int h;
h = 0;
w = 0;
w++;
printf("\n");
h++;
}
/**
* Return: Always 0.
*/
int main(void)
int **grid;
if (grid == NULL)
return (1);
print_grid(grid, 6, 4);
printf("\n");
grid[0][3] = 98;
grid[3][4] = 402;
print_grid(grid, 6, 4);
free_grid(grid, 4);
return (0);
==5013== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==5013== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==5013==
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 98 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 402 0
==5013==
==5013==
==5013==
Repo:
#include "main.h"
#include <stdio.h>
#include <stdlib.h>
/**
* main - check the code for ALX School students.
* Return: Always 0.
*/
char *s;
s = argstostr(ac, av);
if (s == NULL)
return (1);
printf("%s", s);
free(s);
return (0);
./args
will
show you
how
great
am
Repo:
#include "main.h"
#include <stdio.h>
#include <stdlib.h>
/**
* Return: nothing
*/
int i;
printf("%s\n", tab[i]);
/**
*
* Return: 1 if an error occurred, 0 otherwise
*/
int main(void)
char **tab;
if (tab == NULL)
printf("Failed\n");
return (1);
print_tab(tab);
return (0);
ALX$
School$
#cisfun$
Repo:
Concepts
For this project, we expect you to look at this concept:
Resources
Read or watch:
man or help:
• exit (3)
• calloc
• realloc
Learning Objectives
At the end of this project, you are expected to be able to explain to anyone, without the help of
Google:
General
• How to use the exit function
• What are the functions calloc and realloc from the standard library and how to use
them
Copyright - Plagiarism
• You are tasked to come up with solutions for the tasks below yourself to meet with the
above learning objectives.
• You will not be able to meet the objectives of this or any following project by copying and
pasting someone else’s work.
• You are not allowed to publish any content of this project.
• Any form of plagiarism is strictly forbidden and will result in removal from the program.
Requirements
General
• Allowed editors: vi, vim, emacs
• All your files will be compiled on Ubuntu 20.04 LTS using gcc, using the options -Wall -
Werror -Wextra -pedantic -std=gnu89
• All your files should end with a new line
• A README.md file, at the root of the folder of the project is mandatory
• Your code should use the Betty style. It will be checked using betty-style.pl and betty-
doc.pl
• You are not allowed to use global variables
• No more than 5 functions per file
• The only C standard library functions allowed are malloc, free and exit. Any use of
functions like printf, puts, calloc, realloc etc… is forbidden
• You are allowed to use _putchar
• You don’t have to push _putchar.c, we will use our file. If you do it won’t be taken into
account
• In the following examples, the main.c files are shown as examples. You can use them to
test your functions, but you don’t have to push them to your repo (if you do we won’t take
them into account). We will use our own main.c files at compilation. Our main.c files
might be different from the one shown in the examples
• The prototypes of all your functions and the prototype of the function _putchar should be
included in your header file called main.h
• Don’t forget to push your header file
Quiz questions
Great! You've completed the quiz successfully! Keep going! (Show quiz)
Tasks
0. Trust no one
mandatory
#include "main.h"
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
/**
* Return: Always 0.
*/
int main(void)
char *c;
int *i;
float *f;
double *d;
c = malloc_checked(sizeof(char) * 1024);
i = malloc_checked(sizeof(int) * 402);
f = malloc_checked(sizeof(float) * 100000000);
d = malloc_checked(INT_MAX);
free(c);
free(i);
free(f);
free(d);
return (0);
0x1e39010
0x1e39830
0x7f31f6c19010
98
Repo:
#include "main.h"
#include <stdio.h>
#include <stdlib.h>
/**
* Return: Always 0.
*/
int main(void)
char *concat;
printf("%s\n", concat);
free(concat);
return (0);
Best School
FYI: The standard library provides a different function: calloc. Run man calloc to learn more.
#include "main.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/**
* Return: Nothing.
*/
unsigned int i;
i = 0;
if (i % 10)
printf(" ");
printf("\n");
printf("0x%02x", buffer[i]);
i++;
printf("\n");
/**
* Return: Always 0.
*/
int main(void)
char *a;
a = _calloc(98, sizeof(char));
strcpy(a, "Best");
a[97] = '!';
simple_print_buffer(a, 98);
free(a);
return (0);
0x42 0x65 0x73 0x74 0x20 0x53 0x63 0x68 0x6f 0x6f
0x6c 0x21 0x20 0x3a 0x29 0x0a 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
Repo:
#include "main.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/**
* Return: Nothing.
*/
unsigned int i;
i = 0;
if (i % 10)
printf(" ");
printf("\n");
printf("0x%02x", buffer[i]);
i++;
printf("\n");
/**
* Return: Always 0.
*/
int main(void)
{
int *a;
a = array_range(0, 10);
simple_print_buffer(a, 11);
free(a);
return (0);
0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09
0x0a
Repo:
FYI: The standard library provides a different function: realloc. Run man realloc to learn
more.
julien@ubuntu:~/0x0b. more malloc, free$ cat 100-main.c
#include "main.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/**
* Return: Nothing.
*/
unsigned int i;
i = 0;
if (i % 10)
printf(" ");
printf("\n");
printf("0x%02x", buffer[i]);
i++;
printf("\n");
}
/**
* Return: Always 0.
*/
int main(void)
char *p;
int i;
p = malloc(sizeof(char) * 10);
i = 0;
p[i++] = 98;
simple_print_buffer(p, 98);
free(p);
return (0);
0x62 0x62 0x62 0x62 0x62 0x62 0x62 0x62 0x62 0x62
0x62 0x62 0x62 0x62 0x62 0x62 0x62 0x62 0x62 0x62
0x62 0x62 0x62 0x62 0x62 0x62 0x62 0x62 0x62 0x62
0x62 0x62 0x62 0x62 0x62 0x62 0x62 0x62 0x62 0x62
0x62 0x62 0x62 0x62 0x62 0x62 0x62 0x62 0x62 0x62
0x62 0x62 0x62 0x62 0x62 0x62 0x62 0x62 0x62 0x62
0x62 0x62 0x62 0x62 0x62 0x62 0x62 0x62 0x62 0x62
0x62 0x62 0x62 0x62 0x62 0x62 0x62 0x62 0x62 0x62
0x62 0x62 0x62 0x62 0x62 0x62 0x62 0x62 0x62 0x62
0x62 0x62 0x62 0x62 0x62 0x62 0x62 0x62
Repo:
980
674136392357558918799704645242261590747609149899354133505568757708070198930
692012471218551228363894170225521663160100130742587815831438704611827078935
778494086720405550894821603430854826123481453226898830252259887994523292902
811699275321605908105737792665133761261824833211325690248597437196938515601
506881386827400068391218781860166705860541867828432223729721367348241239292
206815929149627431117020868905658535278284448472114084636774164996263864922
950928186789606720847417840215629497894071295951835184641385914179238085331
381201529533354671663434428408642677548077574780815003073211970486780568870
4303461042373101473485092019906795014369069932
Repo:
Learning Objectives
At the end of this project, you are expected to be able to explain to anyone, without the help of
Google:
General
• What are macros and how to use them
• What are the most common predefined macros
• How to include guard your header files
Copyright - Plagiarism
• You are tasked to come up with solutions for the tasks below yourself to meet with the
above learning objectives.
• You will not be able to meet the objectives of this or any following project by copying and
pasting someone else’s work.
• You are not allowed to publish any content of this project.
• Any form of plagiarism is strictly forbidden and will result in removal from the program.
Requirements
General
• Allowed editors: vi, vim, emacs
• All your files will be compiled on Ubuntu 20.04 LTS using gcc, using the options -Wall -
Werror -Wextra -pedantic -std=gnu89
• All your files should end with a new line
• A README.md file, at the root of the folder of the project is mandatory
• Your code should use the Betty style. It will be checked using betty-style.pl and betty-
doc.pl
• You are not allowed to use global variables
• No more than 5 functions per file
• The only C standard library functions allowed are malloc, free and exit. Any use of
functions like printf, puts, calloc, realloc etc… is forbidden
• You are allowed to use _putchar
• You don’t have to push _putchar.c, we will use our file. If you do it won’t be taken into
account
• In the following examples, the main.c files are shown as examples. You can use them to
test your functions, but you don’t have to push them to your repo (if you do we won’t take
them into account). We will use our own main.c files at compilation. Our main.c files
might be different from the one shown in the examples
• Don’t forget to push your header file
• All your header files should be include guarded
Quiz questions
Great! You've completed the quiz successfully! Keep going! (Show quiz)
Tasks
0. Object-like Macro
mandatory
#include "0-object_like_macro.h"
#include "0-object_like_macro.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
int s;
s = 98 + SIZE;
printf("%d\n", s);
return (0);
}
julien@ubuntu:~/0x0c. macro, structures$ gcc -Wall -pedantic -Werror -Wextr
a -std=gnu89 0-main.c -o a
1122
Repo:
#include "1-pi.h"
#include "1-pi.h"
#include <stdio.h>
/**
* Return: Always 0.
*/
int main(void)
float a;
float r;
r = 98;
a = PI * r * r;
printf("%.3f\n", a);
return (0);
}
30171.855
Repo:
2-main.c
02-main.c
Repo:
#include <stdio.h>
#include "3-function_like_macro.h"
#include "3-function_like_macro.h"
/**
* Return: Always 0.
*/
int main(void)
int i;
int j;
i = ABS(-98) * 10;
j = ABS(98) * 10;
return (0);
980, 980
Repo:
#include <stdio.h>
#include "4-sum.h"
#include "4-sum.h"
/**
* Return: Always 0.
*/
int main(void)
int s;
s = SUM(98, 1024);
printf("%d\n", s);
return (0);
1122
Repo:
General
• What are structures, when, why and how to use them
• How to use typedef
Copyright - Plagiarism
• You are tasked to come up with solutions for the tasks below yourself to meet with the
above learning objectives.
• You will not be able to meet the objectives of this or any following project by copying and
pasting someone else’s work.
• You are not allowed to publish any content of this project.
• Any form of plagiarism is strictly forbidden and will result in removal from the program.
Requirements
General
• Allowed editors: vi, vim, emacs
• All your files will be compiled on Ubuntu 20.04 LTS using gcc, using the options -Wall -
Werror -Wextra -pedantic -std=gnu89
• All your files should end with a new line
• A README.md file, at the root of the folder of the project is mandatory
• Your code should use the Betty style. It will be checked using betty-style.pl and betty-
doc.pl
• You are not allowed to use global variables
• No more than 5 functions per file
• The only C standard library functions allowed are printf, malloc, free and exit.
• In the following examples, the main.c files are shown as examples. You can use them to
test your functions, but you don’t have to push them to your repo (if you do we won’t take
them into account). We will use our own main.c files at compilation. Our main.c files
might be different from the one shown in the examples
• Don’t forget to push your header file
• All your header files should be include guarded
Quiz questions
Great! You've completed the quiz successfully! Keep going! (Show quiz)
Tasks
0. Poppy
mandatory
#include <stdio.h>
#include "dog.h"
/**
* Return: Always 0.
*/
int main(void)
my_dog.name = "Poppy";
my_dog.age = 3.5;
my_dog.owner = "Bob";
return (0);
Repo:
• GitHub repository: alx-low_level_programming
• Directory: 0x0E-structures_typedef
• File: dog.h
• Prototype: void init_dog(struct dog *d, char *name, float age, char
*owner);
#include <stdio.h>
#include "dog.h"
/**
* Return: Always 0.
*/
int main(void)
return (0);
Repo:
• GitHub repository: alx-low_level_programming
• Directory: 0x0E-structures_typedef
• File: 1-init_dog.c
#include <stdio.h>
#include "dog.h"
/**
* Return: Always 0.
*/
int main(void)
my_dog.name = "Poppy";
my_dog.age = 3.5;
my_dog.owner = "Bob";
print_dog(&my_dog);
return (0);
}
julien@ubuntu:~/0x0d. structures, typedef$ gcc -Wall -pedantic -Werror -Wex
tra -std=gnu89 2-main.c 2-print_dog.c -o c
Name: Poppy
Age: 3.500000
Owner: Bob
Repo:
Define a new type dog_t as a new name for the type struct dog.
#include <stdio.h>
#include "dog.h"
/**
* Return: Always 0.
*/
int main(void)
dog_t my_dog;
my_dog.name = "Poppy";
my_dog.age = 3.5;
my_dog.owner = "Bob";
printf("My name is %s, and I am %.1f :) - Woof!\n", my_dog.name, my_dog
.age);
return (0);
Repo:
#include <stdio.h>
#include "dog.h"
/**
* Return: Always 0.
*/
int main(void)
dog_t *my_dog;
my_dog = new_dog("Poppy", 3.5, "Bob");
return (0);
Repo:
#include <stdio.h>
#include "dog.h"
/**
* Return: Always 0.
*/
int main(void)
{
dog_t *my_dog;
free_dog(my_dog);
return (0);
==22840== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==22840== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright inf
o
==22840==
==22840==
==22840==
==22840==
Repo:
• Function Pointer in C
• Pointers to functions
• Function Pointers in C / C++
• why pointers to functions?
• Everything you need to know about pointers in C
Learning Objectives
At the end of this project, you are expected to be able to explain to anyone, without the help of
Google:
General
• What are function pointers and how to use them
• What does a function pointer exactly hold
• Where does a function pointer point to in the virtual memory
Copyright - Plagiarism
• You are tasked to come up with solutions for the tasks below yourself to meet with the
above learning objectives.
• You will not be able to meet the objectives of this or any following project by copying and
pasting someone else’s work.
• You are not allowed to publish any content of this project.
• Any form of plagiarism is strictly forbidden and will result in removal from the program.
Requirements
General
• Allowed editors: vi, vim, emacs
• All your files will be compiled on Ubuntu 20.04 LTS using gcc, using the options -Wall -
Werror -Wextra -pedantic -std=gnu89
• All your files should end with a new line
• A README.md file, at the root of the folder of the project is mandatory
• Your code should use the Betty style. It will be checked using betty-style.pl and betty-
doc.pl
• You are not allowed to use global variables
• No more than 5 functions per file
• The only C standard library functions allowed are malloc, free and exit. Any use of
functions like printf, puts, calloc, realloc etc… is forbidden
• You are allowed to use _putchar
• You don’t have to push _putchar.c, we will use our file. If you do it won’t be taken into
account
• In the following examples, the main.c files are shown as examples. You can use them to
test your functions, but you don’t have to push them to your repo (if you do we won’t take
them into account). We will use our own main.c files at compilation. Our main.c files
might be different from the one shown in the examples
• The prototypes of all your functions and the prototype of the function _putchar should be
included in your header file called function_pointers.h
• Don’t forget to push your header file
• All your header files should be include guarded
Quiz questions
Great! You've completed the quiz successfully! Keep going! (Show quiz)
Tasks
0. What's my name
mandatory
#include <stdio.h>
#include "function_pointers.h"
/**
* Return: Nothing.
*/
/**
* Return: Nothing.
*/
unsigned int i;
i = 0;
while (name[i])
else
putchar(name[i]);
i++;
/**
* Return: Always 0.
*/
int main(void)
print_name("Bob", print_name_as_is);
return (0);
Repo:
#include <stdio.h>
#include "function_pointers.h"
/**
* Return: Nothing.
*/
{
printf("%d\n", elem);
/**
* Return: Nothing.
*/
printf("0x%x\n", elem);
/**
* Return: Always 0.
*/
int main(void)
array_iterator(array, 5, &print_elem);
array_iterator(array, 5, &print_elem_hex);
return (0);
98
402
1024
4096
0x0
0x62
0x192
0x400
0x1000
Repo:
#include <stdio.h>
#include "function_pointers.h"
/**
*/
{
return (98 == elem);
/**
*/
/**
*/
/**
* Return: Always 0.
*/
int main(void)
{
int array[20] = {0, -98, 98, 402, 1024, 4096, -1024, -98, 1, 2, 3, 4, 5
, 6, 7, 8, 9, 10, 11, 98};
int index;
printf("%d\n", index);
printf("%d\n", index);
printf("%d\n", index);
return (0);
Repo:
/**
* struct op - Struct op
*/
typedef struct op
char *op;
} op_t;
3-op_functions.c
This file should contain the 5 following functions (not more):
• op_add: returns the sum of a and b. Prototype: int op_add(int a, int b);
• op_sub: returns the difference of a and b. Prototype: int op_sub(int a, int b);
• op_mul: returns the product of a and b. Prototype: int op_mul(int a, int b);
• op_div: returns the result of the division of a by b. Prototype: int op_div(int a, int
b);
• op_mod: returns the remainder of the division of a by b. Prototype: int op_mod(int a,
int b);
3-get_op_func.c
This file should contain the function that selects the correct function to perform the operation
asked by the user. You’re not allowed to declare any other function.
op_t ops[] = {
{"+", op_add},
{"-", op_sub},
{"*", op_mul},
{"/", op_div},
{"%", op_mod},
{NULL, NULL}
};
int i;
3-main.c
This file should contain your main function only.
• You are not allowed to code any other function than main in this file
• You are not allowed to directly call op_add, op_sub, op_mul, op_div or op_mod from
the main function
• You have to use atoi to convert arguments to int
• You are not allowed to use any kind of loop
• You are allowed to use a maximum of 3 if statements
98
102
Error
926
44
Repo:
Note: if you want to translate your opcodes to assembly instructions, you can use, for
instance udcli.
55 48 89 e5 48 83 ec 30 89 7d dc 48 89 75 d0 83 7d dc 02 74 14
[...]
00000000004005f6 <main>:
[...]
• Note 0: je is equivalent to jz
• Note 1: depending on how you write your main function, and on which machine you
compile your program, the opcodes (and by extension the assembly code) might be
different than the above example
Repo:
Resources
Read or watch:
• stdarg.h
• Variadic Functions
• Const Keyword
man or help:
• stdarg
Learning Objectives
At the end of this project, you are expected to be able to explain to anyone, without the help of
Google:
General
• What are variadic functions
• How to use va_start, va_arg and va_end macros
• Why and how to use the const type qualifier
Copyright - Plagiarism
• You are tasked to come up with solutions for the tasks below yourself to meet with the
above learning objectives.
• You will not be able to meet the objectives of this or any following project by copying and
pasting someone else’s work.
• You are not allowed to publish any content of this project.
• Any form of plagiarism is strictly forbidden and will result in removal from the program.
Requirements
General
• Allowed editors: vi, vim, emacs
• All your files will be compiled on Ubuntu 20.04 LTS using gcc, using the options -Wall -
Werror -Wextra -pedantic -std=gnu89
• All your files should end with a new line
• A README.md file, at the root of the folder of the project is mandatory
• Your code should use the Betty style. It will be checked using betty-style.pl and betty-
doc.pl
• You are not allowed to use global variables
• No more than 5 functions per file
• The only C standard library functions allowed are malloc, free and exit. Any use of
functions like printf, puts, calloc, realloc etc… is forbidden
• You are allowed to use the following macros: va_start, va_arg and va_end
• You are allowed to use _putchar
• You don’t have to push _putchar.c, we will use our file. If you do it won’t be taken into
account
• In the following examples, the main.c files are shown as examples. You can use them to
test your functions, but you don’t have to push them to your repo (if you do we won’t take
them into account). We will use our own main.c files at compilation. Our main.c files
might be different from the one shown in the examples
• The prototypes of all your functions and the prototype of the function _putchar should be
included in your header file called variadic_functions.h
• Don’t forget to push your header file
• All your header files should be include guarded
Tasks
0. Beauty is variable, ugliness is constant
mandatory
#include <stdio.h>
#include "variadic_functions.h"
/**
* Return: Always 0.
*/
int main(void)
int sum;
sum = sum_them_all(2, 98, 1024);
printf("%d\n", sum);
printf("%d\n", sum);
return (0);
1122
500
Repo:
#include "variadic_functions.h"
/**
* Return: Always 0.
*/
int main(void)
{
return (0);
Repo:
#include "variadic_functions.h"
/**
* Return: Always 0.
*/
int main(void)
Jay, Django
Repo:
#include "variadic_functions.h"
/**
* Return: Always 0.
*/
int main(void)
{
return (0);
B, 3, stSchool
Repo: