arret
This commit is contained in:
@@ -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);
|
||||||
|
|
||||||
}*/
|
}
|
||||||
|
*/
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -60,7 +64,7 @@ char most_frequent(const char *str){
|
|||||||
free(values);
|
free(values);
|
||||||
return *cha;
|
return *cha;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
int main () {
|
int main () {
|
||||||
|
|
||||||
char test = most_frequent("WRYYYY!1!"); // 'Y'
|
char test = most_frequent("WRYYYY!1!"); // 'Y'
|
||||||
@@ -68,9 +72,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'
|
}
|
||||||
|
|
||||||
|
|
||||||
}*/
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ 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 ++;
|
||||||
|
|||||||
@@ -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,19 +44,20 @@ void my_strapp(char *src, char **dest){
|
|||||||
index ++;
|
index ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
*(dest + index_dest + index + 1) = '\0';
|
*(*dest + index_dest + index) = '\0';
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
int main(){
|
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!
|
||||||
printf("%s", *dest_ptr);
|
printf("%s", *dest_ptr);
|
||||||
free(src);
|
free(src);
|
||||||
free(dest);
|
free(dest);
|
||||||
}*/
|
}
|
||||||
|
|||||||
@@ -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));
|
|
||||||
|
ic = strdup(*(arg + index));
|
||||||
|
rslt = my_weirddup(ic);
|
||||||
|
|
||||||
|
if (rslt != NULL){
|
||||||
printf("%s\n", rslt);
|
printf("%s\n", rslt);
|
||||||
free(rslt);
|
free(rslt);
|
||||||
|
}
|
||||||
|
free(ic);
|
||||||
index ++;
|
index ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,12 +51,12 @@ char *replace(char *str, char *sub){
|
|||||||
index_str ++;
|
index_str ++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
*(rslt + index) = '\0';
|
||||||
return rslt;
|
return rslt;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
int main(){
|
int main(){
|
||||||
|
|
||||||
|
|
||||||
@@ -70,4 +67,4 @@ int main(){
|
|||||||
test = replace("*H*e*l*l*o*", "BIM"); // BIMHBIMeBIMlBIMlBIMoBIM
|
test = replace("*H*e*l*l*o*", "BIM"); // BIMHBIMeBIMlBIMlBIMoBIM
|
||||||
printf("%s\n", test);
|
printf("%s\n", test);
|
||||||
free(test);
|
free(test);
|
||||||
}*/
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user