This commit is contained in:
Debucquoy
2023-09-20 15:18:20 +02:00
parent 00d0cdfaf3
commit 4fd7542f03
228 changed files with 351 additions and 12 deletions

5
bac2/os/chap0/build.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
for i in $(ls *.c); do
gcc $i -o $(echo $i | cut -d '.' -f 1)
done

BIN
bac2/os/chap0/chapitre0.pdf Normal file

Binary file not shown.

BIN
bac2/os/chap0/ex1 Executable file

Binary file not shown.

18
bac2/os/chap0/ex1.c Normal file
View File

@ -0,0 +1,18 @@
#include <stdio.h>
#include <stdlib.h>
unsigned int string_length(char string[]);
int main(int argc, char *argv[])
{
printf("%d", string_length("test"));
return 0;
}
unsigned int string_length(char string[]){
int i = 0;
while(string[i] != '\0'){
i++;
}
return i;
}

BIN
bac2/os/chap0/ex2 Executable file

Binary file not shown.

22
bac2/os/chap0/ex2.c Normal file
View File

@ -0,0 +1,22 @@
#include <stdlib.h>
#include <stdio.h>
void capitalize(char string[]);
int main(int argc, char *argv[])
{
char test[] = "test";
printf("%s\n", test);
capitalize(test);
printf("%s\n", test);
return 0;
}
void capitalize(char string[]){
int i = 0;
while(string[i] != '\0'){
string[i] = string[i] + 'A' - 'a';
i++;
}
}

BIN
bac2/os/chap0/ex3 Executable file

Binary file not shown.

24
bac2/os/chap0/ex3.c Normal file
View File

@ -0,0 +1,24 @@
#include <stdlib.h>
#include <stdio.h>
void replace(char string[], char target, char replacement);
int main(int argc, char *argv[])
{
char test[] = "test";
printf("%s\n", test);
replace(test, 'e', 'a');
printf("%s\n", test);
return 0;
}
void replace(char string[], char target, char replacement){
int i = 0;
while(string[i] != '\0'){
if(string[i] == target){
string[i] = replacement;
}
i++;
}
}

BIN
bac2/os/chap0/ex4 Executable file

Binary file not shown.

26
bac2/os/chap0/ex4.c Normal file
View File

@ -0,0 +1,26 @@
#include <stdlib.h>
#include <stdio.h>
void delete(char string[], char target);
int main(int argc, char *argv[])
{
char test[] = "test test";
printf("%s\n", test);
delete(test, 'e');
printf("%s\n", test);
return 0;
}
void delete(char string[], char target){
int i = 0, offset = 0;
while(string[i] != '\0'){
if(string[i+offset] == target){
offset++;
}
string[i] = string[i+offset];
i++;
}
string[i] = '\0';
}

BIN
bac2/os/chap0/ex5 Executable file

Binary file not shown.

22
bac2/os/chap0/ex5.c Normal file
View File

@ -0,0 +1,22 @@
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
void print_type_stats();
int main(int argc, char *argv[])
{
print_type_stats();
return 0;
}
void print_type_stats(){
printf("int -> %.f\n", pow(2, (sizeof(int) * 8)));
printf("uint -> %.f\n", pow(2, (sizeof(unsigned int) * 8)));
printf("short -> %.f\n", pow(2, (sizeof(short) * 8)));
printf("long -> %.f\n", pow(2, (sizeof(long) * 8)));
printf("float -> %.f\n", pow(2, (sizeof(float) * 8)));
printf("double -> %.f\n", pow(2, (sizeof(double) * 8)));
}

BIN
bac2/os/chap0/ex6 Executable file

Binary file not shown.

23
bac2/os/chap0/ex6.c Normal file
View File

@ -0,0 +1,23 @@
#include <stdlib.h>
#include <stdio.h>
unsigned int count_char_occurence(char string[], char target);
int main(int argc, char *argv[])
{
char test[] = "test test";
printf("%s -> %d\n", test, count_char_occurence(test, 't'));
return 0;
}
unsigned int count_char_occurence(char string[], char target){
int i = 0, ret = 0;
while(string[i] != '\0'){
if(string[i] == target){
ret++;
}
i++;
}
return ret;
}

BIN
bac2/os/chap0/ex7 Executable file

Binary file not shown.

37
bac2/os/chap0/ex7.c Normal file
View File

@ -0,0 +1,37 @@
#include <stdlib.h>
#include <stdio.h>
unsigned int count_word_occurence(char string[], char target[]);
int main(int argc, char *argv[])
{
char test[] = "I am a test and im diggin a test... diggy diggy test...";
printf("%s -> %d\n", test, count_word_occurence(test, "test"));
return 0;
}
unsigned int count_word_occurence(char string[], char target[]){
int sizeoftarget = 0;
while(target[sizeoftarget] != '\0'){
sizeoftarget++;
}
int i = 0, ret = 0;
while(string[i] != '\0'){
if(string[i] == target[0]){
int check = 0;
for (int j = 0; j < sizeoftarget; ++j) {
if(target[j] == string[i+j]){
continue;
}
check = 1;
}
if(!check){
ret++;
}
}
i++;
}
return ret;
}

BIN
bac2/os/chap0/ex8 Executable file

Binary file not shown.

34
bac2/os/chap0/ex8.c Normal file
View File

@ -0,0 +1,34 @@
#include <stdlib.h>
#include <stdio.h>
void print_histogram(char string[]);
int main(int argc, char *argv[])
{
char test[] = "I am a test and im diggin a test... diggy diggy test...";
printf("%s\n",test);
print_histogram(test);
return 0;
}
void print_histogram(char string[]){
char num_letters['z' - 'a'];
for(char i = 0; i <= 'z' - 'a'; i++){
num_letters[i] = 0;
}
char i = 0;
while(string[i] != '\0'){
if(string[i] >= 'a' && string[i] <= 'z'){
num_letters[string[i]-'a']++;
}
i++;
}
for(char i = 0; i <= 'z' - 'a'; i++){
if(num_letters[i] != 0){
printf("%c -> %d\n", i + 'a', num_letters[i]);
}
}
}