Trying to reverse a string using c -


this question has answer here:

platform : c

hi, trying reverse string in following format:

input string: cat

output string: siht si tac

the code have implemented this:

int main() {      char str[100];     char final[100];     int len=0;     int i=0;     char temp[100];     int j=0;      printf("enter string");     gets(str);     len = strlen(str);      printf("%s",str);       for(j=0,i=len-1;i>0;i--)     {         while(j>=len-1)         {             temp[j] = str[i];             final[j] = temp[j];             j++;         }                 }      printf("%s",final);              putchar('\n');      getch();  } 

any suggestions doing wrong?

#include <stdio.h> #include <ctype.h> #include <conio.h> //for getch()  int main(){     char str[100];     char final[100];     char temp[100];     int i, j, k;      printf("enter string :");     scanf("%99[^\n]", str);      printf("\n%s\n", str);      for(k=j=i=0;;++i){         if(isspace(str[i]) || str[i]=='\0'){             while(k){                 final[j++] = temp[--k];             }             if('\0' == (final[j++] = str[i]))                 break;             //k=0;         } else {             temp[k++] = tolower(str[i]);         }     }      printf("%s\n", final);           getch();     return 0; } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -