so i'm making a program that counts letters and only letters and to do that i need to -1 to the counter everytime it goes through a symbol in the loop(ex:?,!,") and below is a draft of the program but it seems that it won't -1 everytime there's a space(space is 32 in ascii) i even tried to see if input[i]==32 is space by making the condition in the for loop input[i]!=32 and it stopped at the space between the first and second word so i don't know why it isn't working in the if statement.
#include <stdio.h>
#include <cs50.h>
int main (void)
{
int p;
string input=get_string("text: ");
for (int i=0;input[i]!='\0';i++)
{
printf("%c",input[i]);
p=i+1;
if (input[i]=='!'||input[i]==32)
{
p=i-1;
}
}
printf("\n");
printf("%i",p);
}```
Aucun commentaire:
Enregistrer un commentaire