question is to create substrings of a string when we encounter space in it.
INPUT & OUTPUT
if input string is like "ram is raju" then output for this should be 3 as all the 3 substrings("ram","raju","is") are different and if input is like "ram is ram" then output should be 2 cause there only two different substrings "ram" and "is".
What I have tried:
this is my line of code for solving the problem.
but im unable to increase the counter from -1.
NOTE
i have started the counter from -1 cause when im comparing substrings for the first time then k's value will surely be not equal to 0 so as to bring the counter to zero i hve done this and due to my line of code i hve to compare e and d before copying d to e for the first time only.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main() {
int t,i=0,j,k,count=-1,l;
char s[100],d[100],e[100];
scanf("%d",&t);
while(t>0)
{
gets(s);
l=strlen(s);
while(i<l)
{
while((i<l)&&(s[i]==' '))
{i++;}
j=0;
while((i<l)&&(s[i]!=' '))
{
d[j]=s[i];
i++;
j++;
}
k=strcmp(e,d);
if(k!=0)
{count++;}
strcpy(e,d);
}
printf("%d",count);
t--;
}
return 0;
}