I want to create program which count longest series of spaces. Here is my code. I always shows 0 no matter how many spaces consist. I am only starting learning c programming so where is the problem?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char string[20];
int count = 0;
int spaces=0, before=0, max=0;
int ch;
printf("enter string\n");
gets(string);
while (1) {
ch = getchar();
if (ch == EOF)
break;
if (ch==' ')
{
if (before=0)
spaces=1;
before=1;
if (spaces>max) max=spaces;
spaces=0;
before=0;
}
printf("Longest serie of spaces %d\n", max);
while (strlen(string)!=0);
system("PAUSE");
return (0);
}
}