-
-
Save Noobzik/fe2cb93adf6dc1ea842f6a403e7a8e4d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
/* | |
* Compléxité n * m en moyenne (pire cas n*n) | |
* @param char *s = La chaine de caractère de départ | |
* @param char e = le caractère à enlever | |
* return ret une chaine de caractère sans la lettre dans e | |
*/ | |
char * remove_caracter_from_string (char *s, char e) { | |
int size = strlen(s); | |
size_t shrinked_size = 0; | |
int i = 0; | |
char *ret; | |
for (i = 0; i < size; i++) { | |
(s[i] != e) ? shrinked_size++ : continue; | |
} | |
if (ret = malloc(shrinked_size * sizeof(char)) == 0) { | |
perror("Erreur de malloc"); | |
return NULL; | |
} | |
for (i = 0; i < size; i++) { | |
(s[i] != e) ? ret[i] = s[i] : continue; | |
} | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment