Skip to content

About

Showcasing simple C language and terminal shell projects made while studying at 42 Rio | 42 école

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

42 Piscine

My solutions to the exercises of the 42 Rio Piscine, the intensive selection bootcamp of the 42 Network.

Language: C Scripting: Shell Style: Norminette School: 42 Rio


About

The Piscine is the admission process of the 42 schools: four weeks of full-time, peer-to-peer learning with no teachers and no lectures. Candidates start from zero and work through daily modules covering the Unix shell and the C language, with exams and group projects along the way.

This repository holds the work I did during my Piscine. It is where I wrote my first lines of C.

Contents

Module Topic Exercises
shell01 Shell scripting: find, awk, tr, id, ifconfig 5
C00 Output with write, loops and conditions 6
C01 Pointers and basic arrays 8
C02 String copying, checking and case conversion 9
C03 String comparison, concatenation and search 5
C04 String length, printing strings and numbers 3
C05 Math: iteration vs. recursion 7
C06 Program arguments (argc / argv) 3
C07 Dynamic memory allocation with malloc 4
rush00 Weekend group project: drawing rectangles 5 patterns
Full exercise list

shell01

Ex File Description
01 print_groups.sh Lists the groups of the user in $FT_USER, separated by commas
02 find_sh.sh Finds every .sh file and prints its name without the extension
03 count_files.sh Counts files and directories from the current directory down
04 MAC.sh Prints the machine's MAC addresses
06 skip.sh Prints every other line of ls -l

C00

Ex Function Description
00 ft_putchar Prints a character
01 ft_print_alphabet Prints the alphabet in lowercase
02 ft_print_reverse_alphabet Prints the alphabet in reverse
03 ft_print_numbers Prints the digits 0–9
04 ft_is_negative Prints N or P depending on the sign of a number
05 ft_print_comb Prints every combination of three different digits in ascending order

C01

Ex Function Description
00 ft_ft Sets an int to 42 through a pointer
01 ft_ultimate_ft Same, through nine levels of pointers
02 ft_swap Swaps two integers
03 ft_div_mod Stores the quotient and remainder of a division
04 ft_ultimate_div_mod Same, storing the results in the operands
05 ft_putstr Prints a string
06 ft_strlen Returns the length of a string
07 ft_rev_int_tab Reverses an array of integers

C02

Ex Function Description
00 ft_strcpy Copies a string
01 ft_strncpy Copies up to n characters
02 ft_str_is_alpha Checks if a string is only letters
03 ft_str_is_numeric Checks if a string is only digits
04 ft_str_is_lowercase Checks if a string is only lowercase letters
05 ft_str_is_uppercase Checks if a string is only uppercase letters
06 ft_str_is_printable Checks if a string is only printable characters
07 ft_strupcase Converts a string to uppercase
08 ft_strlowcase Converts a string to lowercase

C03

Ex Function Description
00 ft_strcmp Compares two strings
01 ft_strncmp Compares up to n characters
02 ft_strcat Appends one string to another
03 ft_strncat Appends up to n characters
04 ft_strstr Finds a substring inside a string

C04

Ex Function Description
00 ft_strlen Returns the length of a string
01 ft_putstr Prints a string
02 ft_putnbr Prints an integer

C05

Ex Function Description
00 ft_iterative_factorial Factorial using a loop
01 ft_recursive_factorial Factorial using recursion
02 ft_iterative_power Power using a loop
03 ft_recursive_power Power using recursion
04 ft_fibonacci n-th Fibonacci number, recursively
05 ft_sqrt Integer square root, or 0 if it is not exact
06 ft_is_prime Checks if a number is prime

C06

Ex Program Description
00 ft_print_program_name Prints the program's own name
01 ft_print_params Prints the arguments, one per line
02 ft_rev_params Prints the arguments in reverse order

C07

Ex Function Description
00 ft_strdup Duplicates a string into newly allocated memory
01 ft_range Returns an array with all integers between min and max
02 ft_ultimate_range Same, through a pointer, returning the size
03 ft_strjoin Joins an array of strings with a separator

Rush 00

The first weekend group project of the Piscine. The goal is to write a function rush(x, y) that draws a rectangle of width x and height y on the terminal, using a specific set of characters for corners and edges. The subject is available in rush00/rush00.pdf.

  • rush00/ex00 – the assigned pattern (rush01)
  • rush00/Bonus – the other four patterns (rush00, rush02, rush03, rush04)

Example, rush(5, 3) with the rush01 pattern:

/***\
*   *
\***/

Usage

Clone the repository:

git clone https://github.com/hadamas/42-piscine.git
cd 42-piscine

C exercises – each file is self-contained and starts with a comment describing the exercise. Compile with the flags used at 42:

cc -Wall -Wextra -Werror C00/ex05/ft_print_comb.c -o ft_print_comb
./ft_print_comb

Some files have their main function commented out, since only the function itself is submitted for evaluation. Uncomment it to test.

Rush – compile all files of a pattern together. Change the values passed to rush() in main.c to draw other sizes:

cc -Wall -Wextra -Werror rush00/ex00/*.c -o rush
./rush

Shell scripts

sh shell01/ex02/find_sh.sh
FT_USER=$(whoami) sh shell01/ex01/print_groups.sh

Piscine rules

Part of the challenge is the set of constraints every exercise must follow:

  • Norminette – 42's strict coding standard: functions of at most 25 lines, at most 80 columns, no for loops, no switch, declarations at the top of the function
  • Restricted functions – each exercise lists the only library functions allowed, often just write or malloc; everything else has to be written by hand
  • Peer evaluation – every submission is reviewed by other candidates and by an automated grader

What I learned

  • Navigating and automating tasks in a Unix shell
  • The foundations of C: types, loops, pointers, strings and arrays
  • Recursion and manual memory management
  • Reading a specification carefully and handling edge cases
  • Working and learning with peers, under time pressure

Author

Alanis Hadama (ahadama-) – 42 Rio GitHub: @hadamas

Looking for what came next? See so_long, a 2D game I built in the 42 Common Core.


These solutions are shared for reference. If you are doing the Piscine, try the exercises on your own first; that is the whole point.

About

Showcasing simple C language and terminal shell projects made while studying at 42 Rio | 42 école

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages