4 Commits

Author SHA1 Message Date
lucas 08707de85d last 2026-02-02 05:05:29 +01:00
lucas 85c5f535d8 zf 2026-02-02 04:56:58 +01:00
lucas 390f7ef7d9 arret 2026-02-02 04:54:21 +01:00
lucas 49213b1343 arret 2026-02-02 04:52:09 +01:00
6 changed files with 63 additions and 51 deletions
+8 -6
View File
@@ -1,8 +1,10 @@
#include <stdlib.h> #include <stdlib.h>
//#include <stdio.h> #include <stdio.h>
int *count(int n){ int *count(int n){
if (n < 1) return NULL; if (n < 1) return NULL;
int *p = malloc(n);
int *p = malloc(n * sizeof(int));
if(p == NULL) return NULL; if(p == NULL) return NULL;
while (n != 0){ while (n != 0){
@@ -14,15 +16,15 @@ int *count(int n){
} }
/* /*
int main(){ int main(){
int *rslt = count(5); int *rslt = count(5123456);
int index = 0; int index = 0;
while(*(rslt + index)){ while(*(rslt + index)){
printf("%i", *(rslt + index)); printf("%i, ", *(rslt + index));
index ++; index ++;
} }
free(rslt); free(rslt);
}*/ }
*/
+10 -7
View File
@@ -15,16 +15,20 @@ char most_frequent(const char *str){
//index //index
//index_clc //index_clc
if (str == NULL) return '\0';
char *cha = malloc(2 * sizeof(char)); char *cha = malloc(2 * sizeof(char));
//{ lettre, temp} //{ lettre, temp}
if (cha == NULL) return 0; if (cha == NULL) return '\0';
*cha = 0; // lettre *cha = 0; // lettre
*(cha + 1) = 0; //lettre pendant le clc *(cha + 1) = 0; //lettre pendant le clc
int *values = malloc (4 * sizeof(int)); int *values = malloc (4 * sizeof(int));
if(values == NULL) return 0 ; if(values == NULL) {
free(cha);
return '\0' ;
}
//{ max, temp max, index, index_clc} //{ max, temp max, index, index_clc}
*values = 0; // Maximum *values = 0; // Maximum
@@ -57,8 +61,10 @@ char most_frequent(const char *str){
(*(values + 2)) ++; (*(values + 2)) ++;
} }
char rslt = *cha;
free(values); free(values);
return *cha; free(cha);
return rslt;
} }
/* /*
int main () { int main () {
@@ -68,9 +74,6 @@ int main () {
test = most_frequent("ORA ORA ORA!"); // 'O' test = most_frequent("ORA ORA ORA!"); // 'O'
printf("%c\n",test); printf("%c\n",test);
test = most_frequent("hello warudo!"); // 'l' test = most_frequent('\0'); // 'l'
printf("%c\n", test); printf("%c\n", test);
most_frequent("oRA ora oRa?"); // 'o'
}*/ }*/
+3 -3
View File
@@ -6,7 +6,7 @@
int *my_factor(int n){ int *my_factor(int n){
if (n <= 0) return NULL; if (n <= 0) return NULL;
if (n == 1) return 1; //if (n == 1) return 1;
int cnt = 0; int cnt = 0;
int tmp = n; int tmp = n;
@@ -28,11 +28,11 @@ int *my_factor(int n){
tmp = n; tmp = n;
div = 2; div = 2;
while (temps > 1) { while (tmp > 1) {
if (tmp % div == 0){ if (tmp % div == 0){
*(kebab + index) = div; *(kebab + index) = div;
index ++; index ++;
tmp = tmp / div; tmp = tmp / div;
} }
else div ++; else div ++;
} }
+6 -3
View File
@@ -7,6 +7,7 @@ char *strdup(const char *s);
void my_strapp(char *src, char **dest){ void my_strapp(char *src, char **dest){
if (src == NULL || dest == NULL) return; if (src == NULL || dest == NULL) return;
if (*dest == NULL) return;
//taille src //taille src
int index = 0; int index = 0;
@@ -17,10 +18,11 @@ void my_strapp(char *src, char **dest){
while (*(*dest + index_dest)) index_dest ++; while (*(*dest + index_dest)) index_dest ++;
//realloc des dest avec la taille de src //realloc des dest avec la taille de src
*dest = realloc(*dest, index + index_dest + 1); char *new = realloc(*dest, (index + index_dest + 1) * sizeof(char)) ;
//int *dest = realloc(*dest, index); //int *dest = realloc(*dest, index);
if (dest == NULL) return; if(new == NULL) return;
*dest = new;
index = 0; index = 0;
/*while(*(new + index_dest)){ /*while(*(new + index_dest)){
@@ -42,7 +44,7 @@ void my_strapp(char *src, char **dest){
index ++; index ++;
} }
*(dest + index_dest + index + 1) = '\0'; *(*dest + index_dest + index) = '\0';
} }
@@ -51,6 +53,7 @@ int main(){
char *src = strdup("World!"); char *src = strdup("World!");
char *dest = strdup("Hello, "); char *dest = strdup("Hello, ");
//char *dest = '\0';
char **dest_ptr = &dest; char **dest_ptr = &dest;
my_strapp(src, dest_ptr); // Hello, World! my_strapp(src, dest_ptr); // Hello, World!
+17 -10
View File
@@ -1,6 +1,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
char *strdup(const char *s);
char *my_weirddup(char *src){ char *my_weirddup(char *src){
if(src == NULL) return NULL; if(src == NULL) return NULL;
@@ -10,7 +12,7 @@ char *my_weirddup(char *src){
index ++; index ++;
} }
char *str = malloc(index); char *str = malloc((index + 1) * sizeof(char));
if(str == NULL) return NULL; if(str == NULL) return NULL;
//printf("test"); //printf("test");
@@ -29,7 +31,7 @@ char *my_weirddup(char *src){
} }
//min //min
if (lettre > 96 && lettre < 124) { else if (lettre > 96 && lettre < 123) {
if (lettre == 'z') lettre = 'a'; if (lettre == 'z') lettre = 'a';
else lettre ++; else lettre ++;
} }
@@ -38,22 +40,27 @@ char *my_weirddup(char *src){
index ++; index ++;
} }
*(str + index + 1) = '\0'; *(str + index) = '\0';
return str; return str;
} }
//TODO MARCHE MAIS À COMPLETER
int main(int args ,char **arg){ int main(int args ,char **arg){
int index = 1; int index = 1;
char *rslt = ""; char *rslt = NULL;
char *ic = NULL;
while(index < args){ while(index < args){
rslt = my_weirddup(*(arg + index));
printf("%s\n",rslt);
free(rslt);
index ++;
}
ic = strdup(*(arg + index));
rslt = my_weirddup(ic);
if (rslt != NULL){
printf("%s ; %s\n", ic ,rslt);
free(rslt);
}
free(ic);
index ++;
}
} }
+16 -19
View File
@@ -6,39 +6,36 @@ char *replace(char *str, char *sub){
//clc taille sub //clc taille sub
//nbr * x taille sub //nbr * x taille sub
int len_fin = 0; if(str == NULL || sub == NULL) return NULL;
//clc taille str
int index = 0;
int nb_etoile = 0;
while( *(str + index)){
if ( *(str + index) == '*') nb_etoile ++;
index ++;
}
len_fin = index;
//clc taille sub //clc taille sub
index = 0; int index = 0;
while (*(sub + index)) index ++; while (*(sub + index)) index ++;
//longueur finale int index_str = 0;
len_fin += nb_etoile * index; int nb_etoile = 0;
while( *(str + index_str)){
if ( *(str + index_str) == '*') nb_etoile ++;
index_str ++;
}
int len_fin = index_str - nb_etoile + ( index * nb_etoile);
char *rslt = malloc(len_fin); char *rslt = malloc((len_fin + 1) * sizeof(char));
if (rslt == NULL) return NULL; if (rslt == NULL) return NULL;
index = 0; index = 0;
int index_str = 0; index_str = 0;
int index_sub = 0; int index_sub = 0;
//parcours total //parcours total
while(*(str + index_str)){ while(*(str + index_str)){
index_sub = 0;
//si le char est une etoile //si le char est une etoile
if (*(str + index_str) == '*'){ if (*(str + index_str) == '*'){
index_sub = 0;
//copie de sub dans rslt //copie de sub dans rslt
while(*(sub + index_sub)){ while(*(sub + index_sub)){
*(rslt + index) = *(sub + index_sub); *(rslt + index) = *(sub + index_sub);
@@ -54,7 +51,7 @@ char *replace(char *str, char *sub){
index_str ++; index_str ++;
} }
*(rslt + index) = '\0';
return rslt; return rslt;
} }