I'm trying to reverse the sentence but I can't add space between two words . It crashes when i try. I assign sentence in the str to the sent in the code.
void reverse(char *str)
{
char sent[100];
int i=lenght(str);
int t=0;
while(i>=-1)
{
if(str[i]==' ' || str[i]=='\0' || i==-1)
{
int k=i+1;
while(str[k]!=' ' && str[k]!='\0')
{
sent[t]=str[k];
k++;
t++;
}
}
i--;
}
// INPUT: THIS SENTENCE IS AN EXAMPLE
// VARIABLE SENT= EXAMPLEANISSENTENCETHIS