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 Answer 1

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') Commented Aug 21, 2020 at 15:22
  • was it perhaps because you misspelled isalpha?
    – Cliff B
    Commented Aug 21, 2020 at 19:03
  • Ah yes, thank you. Commented Aug 25, 2020 at 21:49

You must log in to answer this question.

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