sami sam

sami sam

  • NA
  • 40
  • 30.3k

Write a program that will reverse the letters in a string. Eg if s1 is assigned "horse" then s2 ends up as "esroh"

Aug 13 2012 3:24 AM

the output is an empty black screen what I know there is something I did wrong with the loop:

Write a program that will reverse the letters in a string. Eg

                if s1 is assigned "horse" then s2 ends up as "esroh"



#include <stdio.h>

#include <string.h>

char s1[80], s2[80];

int i,j;

int main (){

                strcpy(s1, "hourse");

                i=strlen (s1)-1;

                j=0;

                while(i>=0){

                s2[j]=s1[i];

                i--;

                j--;

                s2[j]='\0';

                }

}


Answers (1)