reverse of given string worlds c program -asr

#include <stdio.h>
void main(){
   
    int i=0,len,num=0,a[10],j,f,l;
    char s[100];
   
   
   
    while(1){
        s[i]=getchar();
        if(s[i]=='\n'){
                len=i;           //get chatacters
                s[i]=' ';        //set last character as space
            break;   //break if enter pressed
        }

       
        i++;
    }
   
   
for(i=0;i<len;i++){
    if(s[i]==' '){
        a[num]=i+1;     //detect the positions where space is present
        num++;
    }
   
}   

a[num]=len+1;    //insert length in top index + incremented for including the space that we assigned

for(i=num;i>=0;i--){
   
    f=a[i];
    l=a[i-1];
for(j=l;j<f;j++){
    printf("%c",s[j]);   //prints reverse
   
}
}






}



Comments

Popular posts from this blog

aaabb to32 ,aabbb to a2b3 convert in c-asr

a2b3 output aabbb c program and beautiful use of getchar() ,isdigit() ,atoi() functions and stdlib.h header file-asr

C program to print square spiral number pattern - asr