Add strlen
This commit is contained in:
parent
2bb6b24251
commit
b2b6656d32
2 changed files with 32 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -33,3 +33,4 @@ conversion-majuscule
|
|||
mirroir
|
||||
creation-mot-de-passe
|
||||
strcmp
|
||||
strlen
|
||||
|
|
31
programmation-c-cpp/tp3/strlen.c
Normal file
31
programmation-c-cpp/tp3/strlen.c
Normal 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;
|
||||
}
|
Loading…
Reference in a new issue