1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
#include <Stdio.h>
main()
{
printf("%s \n", "Entrez un message n'ayant pas plus que 50 caractères:");
char entree[51];
int i = 0;
fgets(entree, sizeof(entree), stdin);
long nombre_espace = 0;
long nombre_tab = 0;
long nombre_fin_ligne = 0;
char courant;
while (fgets(entree, sizeof(entree), stdin) != NULL)
{
while ((courant = entree[i]) != '\0')
{
if (courant == ' ')
{
nombre_espace++;
}
if (courant == '\t')
{
nombre_tab++;
}
if (courant == '\n')
{
nombre_fin_ligne++;
}
i++;
}
printf("%s %ld \n %s %ld \n %s %ld \n", "Nombre d'espaces : ", nombre_espace, "Nombre de tabulations :", nombre_tab, "Nombre de fin de lignes : ", nombre_fin_ligne);
} |
Partager