Skip to content

Instantly share code, notes, and snippets.

@Noobzik
Last active January 26, 2020 09:24
Show Gist options
  • Save Noobzik/fe2cb93adf6dc1ea842f6a403e7a8e4d to your computer and use it in GitHub Desktop.
Save Noobzik/fe2cb93adf6dc1ea842f6a403e7a8e4d to your computer and use it in GitHub Desktop.
#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