I'm trying to find bug in the following program.
If I give input as "This is a test", output shows "This Is A". I'm trying to find out why "Test" is missing.
Please help me to understand the problem. Thanks in advance.
#include<stdio.h>
#include<string.h>
int main()
{
char str[1000], word[100];
int i, j, length, is_word_started;
gets(str);
length=strlen(str);
is_word_started=0;
for(i=0, j=0; i<length; i++)
{
if(str[i]>='a' && str[i]<='z')
{
if(is_word_started==0)
{
is_word_started=1;
word[j]='A'+str[i]-'a';
j++;
}
else
{
word[j]=str[i];
j++;
}
}
else if(str[i]>='A' && str[i]<='Z' || str[i]>='0' && str[i]<='9')
{
if(is_word_started==0)
{
is_word_started=1;
}
word[j]=str[i];
j++;
}
else
{
if(is_word_started==1)
{
is_word_started=0;
word[j]='\0';
printf("%s\n", word);
j=0;
}
}
}
return 0;
}