How to reverse a string using array?

Showing Answers 1 - 15 of 15 Answers

deepam chakraborty

  • Sep 10th, 2006
 

after inserting an string in an array place a counter to find the length of array, then start with for loop. function shown below

for (i=n-1;i>=o;i--)

{

  printf("%c",a[i]);

}

/*a[ ] is the string variable*/

/*n is the size of thr string*/  

  Was this answer useful?  Yes

santhosh kumar r

  • Oct 7th, 2006
 

#include<stdio.h>

#include<conio.h>

#include<string.h>

void main()

{

  char name[25],rev[25];

  int i,l;

  printf("enter the name");

 gets(name);

  l=strlen(name);

  for(i=0;i<l;i++)

     {

         name[i]=rev[l-1-i];

          i++;

      }

getch();

} 

 

 

 

vishal

  • Nov 30th, 2006
 

/*without using standard functions*/

#include<stdio.h>

#include<string.h>

#include <conio.h>

main()

{

  char s[40],c,r[40];

  int i,j,p;

  clrscr();

  printf("Enter the string:");

  gets(s);

  for(i=0;s[i]!='';i++);

             j=i;

  printf("The original string is:%s",s);

  printf("nThe reverse string is:");

  for(p=j-1,i=0;p>=0;p--,i++)

 r[i]=s[p];

  r[i]='';

  printf("The reverse string is:%s",r);

  getch();

 }

  Was this answer useful?  Yes

R.S.Jayasathyanarayanan

  • Dec 16th, 2006
 

#include#include#includevoid main(){ char name[25],rev[25]; int i,l; printf("enter the name"); gets(name); l=strlen(name)-1; for(i=l,j=0;i>=0l;i--,j++) { name[i]=rev[j]; }getch();}

  Was this answer useful?  Yes

jintojos

  • Jun 16th, 2008
 

#include #include char fun(); int i; char str[10]; void main() { clrscr(); printf("Enter The String :"); fun(); str[i]=''; printf("nThe Revers Is :%s",str); getch(); } char fun() { char ch; if((ch=getchar())!='n') fun(); if(ch!='n') str[i++]=ch; }

  Was this answer useful?  Yes

ya this is as simple as,

void Reverse(char a[])
{
     register int i,j;  //becoz i and j is used frequently
     char temp;
    
     for(i=0,j=strlen()-1;i<j;i++,j--)
         temp = a[i], a[i] = a[j], a[j] = temp;
}


freakGrl

  • Jul 17th, 2011
 

Reverse a string using array.............plz comment on this

Code
  1. # include <iostream.h>

  2. # include <string.h>

  3. 'x0'"enter string to reverse it  ""enter string to reverse it  ""enter Nos to reversed "

  Was this answer useful?  Yes

chita ranjan patra

  • Aug 3rd, 2011
 

I am giving only the logic,using the pointer
implement this logic as your requirement
it will be effective

Code
  1.  

  Was this answer useful?  Yes

moumita

  • Mar 2nd, 2015
 

no, it is not at all helpful. Sumita Arora se chapke jyada bhao mat kha

  Was this answer useful?  Yes

shiwang

  • Dec 4th, 2016
 

Code
  1. #include <math.h>

  2. #include <stdio.h>

  3. #include <string.h>

  4. #include <stdlib.h>

  5. #include <assert.h>

  6. #include <limits.h>

  7. #include <stdbool.h>

  8. "%d""

  9. %d""%d"

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions