I am trying to construct a simple programme which counts the number of letters in a user's input. My idea was to use a for loop which would loop for each letter in a string, increment a counter, and return the final counter total at the end. However, I do not want the programme to count spaces- I attempted to use the isalpha function to do this- but I seem to be formatting it incorrectly. Also, the way I tried to make the counter NOT increment for a space was with c = c, however, this also seems to be incorrect. Here is the code I have written so far:
int c = 0;
int main(void)
{
string s = get_string("Input: ");
printf("Output: ");
for (int i = 0; i < strlen(s); i++)
{
if( s[i] (isalpha))
{
c++;
}
else
{
c = c;
}
}
printf("%i\n", c);
}
isalphais effectively a function call. (It is a function call or a function-like macro.) A function call is written asname(),name(argument), orname(argument,…)according to whether it is passing zero, one, or more arguments.isalphatakes a single argument. That argument should be anunsigned charvalue. So you can call it asisalpha((unsigned char) s[i]). Yourifstatement should look like:Your program should also contain
#include <ctype.h>to include the header that declaresisalpha.