0

I am able to figure out the number of letters and spaces (the answer is 300) with the code below. How do I write a command to exclude the spaces? A hint would be appreciated. Thank you.

'''

#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <ctype.h>

int main(void)
{
// Prompt for text from the user
string s = get_string("Input: ");

// Count number of characters up until '\0'
    int n = 0;
    while (s[n] != '\0')
    {
        n++;
    }
    printf("%i\n", n);
}

'''
1

Hint: The function isalpha(), along with it's cousins like isspace() and ispunct(), etc., are your friends. ;-)

3
  • I couldn't get islapha() to work but instead used: if ((text[i] >= 'a' && text[i] <= 'z') Aug 21 '20 at 15:22
  • was it perhaps because you misspelled isalpha?
    – Cliff B
    Aug 21 '20 at 19:03
  • Ah yes, thank you. Aug 25 '20 at 21:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .