I know how to count number of words in a string but the problem with my code or what I am not able to do is, when I enter multiple ;; it shows as a word. The normal method is to do a count++ when a space is detected but what in case of multiple ;; or ]] or any special case. How do I make the complier to ignore special characters?
My current code is
#include <stdio.h>
#include <string.h>
void main()
{
char s[200];
int count = 0, i;
printf("enter the string\n");
scanf("%[^\n]s", s);
for (i = 0;s[i] != '\0';i++)
{
if (s[i] == ' '&& s[i+1]!= ' ')
count++;
}
printf("number of words in given string are: %d\n", count + 1);
}