samedi 29 décembre 2018

How many characters are in given array but spaces

I am trying to find out how many characters are in the given array except blanks but it's not working, k supposed to count blanks and substract them from i[characters + blanks] but it doesn't.

int i= 0;
int n= 0;
int k= 0;
char c[256] = {};
fgets(c ,256, stdin);

while(c[i] != '\0' ){
     if(c[i] == ' '){
             i++;
             k++;
             continue;}
i++;}


printf("%d",i-k);

Aucun commentaire:

Enregistrer un commentaire