GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Concepts
Go To First  |  Previous Question  |  Next Question 
 Concepts  |  Question 4 of 24    Print  
Write a C program to reverse the string without using strrev() function?

  
Total Answers and Comments: 28 Last Update: September 23, 2009     Asked by: vigneshwaran 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: Rohan
 

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

void main()
{
   char str[10],temp;
   int i,len;
   printf("Enter String : ");
   scanf("%s",str);
   len=strlen(str)-1;
   for(i=0;i<strlen(str)/2;i++)
   {
      temp=str[i];
      str[i]=str[len];
      str[len--]=temp;
   }
   printf("%s",str);
   getch();

}



Above answer was rated as good by the following members:
yuvarasu
  Sorting Options  
  Page 1 of 3   « First    1    2    3    >     Last »  
January 29, 2006 02:14:00   #1  
dilipiyer Member Since: January 2006   Contribution: 11    

RE: write a c program to reverse the string without us...
#include<stdio.h>
#include<string.h>
main()
{
char str[50] revstr[50];
int i 0 j 0;
printf( Enter the string to be reversed : );
scanf( s str);
for(i strlen(str)-1;i> 0;i--)
{
revstr[j] str[i];
j++;
}
revstr[j] '\0';
printf( Input String : s str);
printf( \nOutput String : s revstr);
getch();
}

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
February 11, 2006 22:40:21   #2  
Rohan Member Since: November 2005   Contribution: 11    

RE: write a c program to reverse the string without us...

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

void main()
{
char str[10] temp;
int i len;
printf( Enter String : );
scanf( s str);
len strlen(str)-1;
for(i 0;i<strlen(str)/2;i++)
{
temp str[i];
str[i] str[len];
str[len--] temp;
}
printf( s str);
getch();

}


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
February 18, 2006 10:05:55   #3  
Rohan Member Since: November 2005   Contribution: 11    

RE: write a c program to reverse the string without us...

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

void main()
{
char *str;
int i len;

//not using any temp variable and assume we can use only string array and length

printf( Enter String : );
scanf( s str);
len strlen(str)-1;
for(i 0;i<strlen(str)/2;i++)
{
str[i]+ str[len];
str[len] str[i]-str[len];
str[i] str[i]-str[len--];
}
printf( Reverse String is : s str);
getch();
}


 
Is this answer useful? Yes | No
March 14, 2006 08:44:58   #4  
umashankar        

RE: write a c program to reverse the string without us...
Can u pls guide me to reverse a string using recursion without using assignment operator.Thanking uUm
 
Is this answer useful? Yes | No
April 17, 2006 03:22:20   #5  
umaira        

RE: write a c program to reverse the string without us...
can u send me the program to reverse a string using recursion.And the input should be a list of characters i.e not getting the input as string.
 
Is this answer useful? Yes | No
May 13, 2006 06:16:17   #6  
Venkatesh        

RE: write a c program to reverse the string with in the same string
How to write a c program to reverse the string with in the same string? I.e No other string variables should be used. Not even builn functions also.
 
Is this answer useful? Yes | No
July 04, 2006 09:29:42   #7  
Syed Aftab        

RE: write a c program to reverse the string without us...

program to reverse a string using recursive function:

---------------------------------------------------

void reverse (int index char *str ) ;

int main (void)

{

char name[100];

printf ( Enter a mutli-word string ) ;

gets(name) ;

reverse (strlen(name) name ) ;

}

void reverse (int index char *str )

{

if (--index < 0 )

{

return ;

}

else

{

putchar ( *(str + index) ) ;

reverse (index str) ;

}

}

Logic:

-----

For eg : let's say the user has entered 50 characters.

then index is initially 50.

when reverse() function is called for the first time then

index will be 50 .we first decrement the index by 1 so that

it will become 49 and i am printing the 49th character i.e last

character in the string then reverse() function is called again

with index as 49 and str pointing to 49th character and again

the index will be decremented by 1 so that it will become 48 this

will continue until zeroth index is reached.

i hope this will solve the problem that you have reported for any

queries you can mail me.

Regards

Syed


 
Is this answer useful? Yes | No
July 29, 2006 15:41:37   #8  
neha        

RE: write a c program to reverse the string without us...
#include<stdio.h>
int main()
{
char c;
c getchar();

if(c! '.') //dot is to terminate when u r finished given the string char by char/

main();//calling main recursively

putchar(c);
return 0;
}

 
Is this answer useful? Yes | No
August 13, 2006 12:00:35   #9  
BHARADWAJ        

RE: write a c program to reverse the string without using another string as u have taken but by taking single char
excellent code please give the solution for this RE: write a c program to reverse the string by taking single char i.e by putting each time to that char
 
Is this answer useful? Yes | No
September 12, 2006 02:14:48   #10  
Madhu Chandra        

RE: write a c program to reverse the string without us...
Too Good man!!!
 
Is this answer useful? Yes | No
  Page 1 of 3   « First    1    2    3    >     Last »  


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape