2 Commits

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