I wrote this code in C, where I wanted to extract words from str
, then store them in char word[]
(one by one), and send it to another function- palindrome. However, the words are not being formed properly. I'm new to this language so I don't want to use pointers or something else. I want to do it in the most simple way possible. Could you please suggest modifications to the code so that the words get formed properly?
int main()
{
char str[100];
int a=0, l, p=0;
printf("Enter the text \n");
gets(str);
l=strlen(str);
for(int i=0;i<l;i++)
{
char word[100]; int a=0;
if(str[i]==' '||str[i]=='\0')
{
for(int j=p;j<i;j++)
{
word[a]=str[j];
a++;
}
printf("This \n");
puts(word);
palindrome(a,word);
}
}
return 0;
}