#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main(){
     char *str=NULL;
     size_t length = 0;
     
     if(getline(&str,&length,stdin) == -1){//only use for till /n new line input
         printf("no input");
         return 1;
     }
     
     //int len = strlen(str); no need to use 
     int printed_first_word = 0;
     int word = 0;
     for(int i=length;i>=0;i--){//lenght takes from input user it calculates
         if(str[i]==' '){
             str[i] = '\0';//| i | s | \0| a | d | a | r | s | h | \0|   | \n | \0 |
             printf("%s ",&str[i+1]);//pass address of last 1st str, this is how it is        i+1          i
             printed_first_word = 1;
             word++;
         }
     }
     if (!printed_first_word) {
         // There was no whitespace in the input string
         printf("%s", str);
     }
     
     printf("%s", str);
     printf("\nno of words:%d",word+1);
     free(str);
     return 0;
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: