Add strlen

This commit is contained in:
flyingscorpio@arch-desktop 2021-11-14 23:36:52 +01:00
parent 2bb6b24251
commit b2b6656d32
2 changed files with 32 additions and 0 deletions

1
.gitignore vendored
View file

@ -33,3 +33,4 @@ conversion-majuscule
mirroir mirroir
creation-mot-de-passe creation-mot-de-passe
strcmp strcmp
strlen

View file

@ -0,0 +1,31 @@
/* strlen */
#include <stdio.h>
#include <stdlib.h>
int strlength(char*);
int main() {
char mot[100];
int i = 0;
printf("Ecrire un mot : ");
fgets(mot, 100, stdin);
while (mot[i] != '\n') i++;
mot[i] = '\0';
printf("Taille de la string : %d\n", strlength(mot));
return 0;
}
int strlength(char *mot) {
int i = 0;
while (mot[i] != '\0') {
i++;
}
return i;
}