ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   To Refer this Site to Your Friends   Click Here
Google
 
Categories  >>  Code Snippets  >>  Programming Code  >>  C Code
 
 


 

 
 C Code interview questions  C Code Interview Questions
 C++ Code interview questions  C++ Code Interview Questions
 VC++ Code interview questions  VC++ Code Interview Questions
 Java Code interview questions  Java Code Interview Questions
 Dot Net Code interview questions  Dot Net Code Interview Questions
 Visual Basic Code interview questions  Visual Basic Code Interview Questions
 Programming Code AllOther interview questions  Programming Code AllOther Interview Questions
Question
How to reverse a String without using C functions ?
 Question Submitted By :: Sureshsan
I also faced this Question!!     Rank Answer Posted By  
 
  Re: How to reverse a String without using C functions ?
Answer
# 1
my_strrev(char str[Max]){
    int i; // pointing to base adress
    int l; //pointing to last address strlen(str) -1th position
    char temp;
    for(i=0,l=strlen(str)-1;i<=l; i++ ,j--)
    {
      temp=str[i];
      str[i]=str[l];
      str[l]=temp;
    }
    return str;
}
 
Is This Answer Correct ?    2 Yes 6 No
Amaresh Ch Das
 
  Re: How to reverse a String without using C functions ?
Answer
# 2
char * rev(char * str){
 int temp;  
 for(int j=0;str[j];j++);     
 for(int i=0;i<j;i++,j--){
        temp=str[i];
        str[i]=str[j];
        str[j]=temp;
    } 
 return str;
}
 
Is This Answer Correct ?    6 Yes 1 No
Guest
 
 
 
  Re: How to reverse a String without using C functions ?
Answer
# 3
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
int main()
{
int i=0,l,l1;
char str[100];
cout<<"enter string:";
gets(str);
while(str[i])
i++;
l=i;
for(i=0;i<=(l-1)/2;i++)   //n/2 steps!!no extra memory
{
char t=str[i];
str[i]=str[l-i-1];
str[l-i-1]=t;
}
str[l]=0;
cout<<"\n\nreversed string is:"<<str;
getch();
return 0;
}
 
Is This Answer Correct ?    2 Yes 0 No
Raghuram.A
 
  Re: How to reverse a String without using C functions ?
Answer
# 4
char * rev_string (char * str)
{
char temp;
int i , j;
for (i = 0 ; str[i]!= NULL ; i++);

for(j = 0 ; j < i ; j++ , i--)
{
      temp = str[j];
      str[j] = str[i];
      str[i] = temp;
}

return str;
}
 
Is This Answer Correct ?    3 Yes 0 No
Shruti
 
  Re: How to reverse a String without using C functions ?
Answer
# 5
the above is slightly wrong
this is the corrected one..

char * rev_string (char * str)
{
char temp;
int i , j;
for (i = 0 ; str[i]!= '\0' ; i++);

for(j = 0 ; j < i ; j++ , i--)
{
      temp = str[j];
      str[j] = str[i];
      str[i] = temp;
}

return str;
}
 
Is This Answer Correct ?    6 Yes 0 No
Shruti
 
  Re: How to reverse a String without using C functions ?
Answer
# 6
#include<stdio.h>

void reverse(char *);

void main()
{
	char str[]="Hello";

	reverse(str);
	printf("Reverse String is %s",str);
	
}

void reverse(char *p)
{

	char *q=p;
	while(*++q!='\0');
	q--;

	while(p<q)
	{
		*p=*p+*q;
		*q=*p-*q;
		*p=*p-*q;
		p++;
		q--;
	}

}
 
Is This Answer Correct ?    4 Yes 1 No
Atul Kabra
 
  Re: How to reverse a String without using C functions ?
Answer
# 7
char * rev_string (char * str)
{
char temp;
int i , j;
for (i = 0 ; str[i]!= '\0' ; i++);
i--;

for(j = 0 ; j < i ; j++ , i--)
{
      temp = str[j];
      str[j] = str[i];
      str[i] = temp;
}

return str;
}
 
Is This Answer Correct ?    2 Yes 0 No
Shruti
 
  Re: How to reverse a String without using C functions ?
Answer
# 8
#include<muthu.h>
main()
 {
   printf("\nthe reverse string is:",reversemuthu(s1);
 }

output:
 original string is: muthu
 the reverse string is: uthum
   
Thanks and recgards:
   prof.muthu ph:9962940220
 you can call me any time any where...!
 
Is This Answer Correct ?    2 Yes 2 No
Prof.muthu
 

 
 
 
Other C Code Interview Questions
 
  Question Asked @ Answers
 
How can u say that a given point is in a triangle? 1. with the co-ordinates of the 3 vertices specified. 2. with only the co-ordinates of the top vertex given.  1
how to return a multiple value from a function? Wipro4
Write a program that find and print how many odd numbers in a binary tree  1
How we will connect multiple client ? (without using fork,thread) TelDNA2
print a semicolon using Cprogram without using a semicolon any where in the C code in ur program!! Tata-Elxsi14
How do I write a program to print proper subset of given string . Eg :input: abc output:{},{a},{b},{c},{a,b},{a,c},{b,c}, {a,b,c}.I desperately need this program please mail me to saravana6m@gmail.com Deshaw8
Sorting entire link list using selection sort and insertion sort and calculating their time complexity NetApp1
plz send me all data structure related programs  1
Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal.  5
How to return multiple values from a function?  4
how can u draw a rectangle in C Wipro24
How to read a directory in a C program?  3
print numbers till we want without using loops or condition statements like specifically(for,do while, while swiches, if etc)!  7
What is the main difference between STRUCTURE and UNION?  3
Find the largest number in a binary tree Infosys4
Given an array of characters which form a sentence of words, give an efficient algorithm to reverse the order of the words (not characters) in it. Microsoft4
How to reverse a String without using C functions ? Wipro8
Given an array of characters which form a sentence of words, give an efficient algorithm to reverse the order of the words (not characters) in it. Wipro2
Finding a number which was log of base 2 NetApp1
to remove the repeated cahracter from the given caracter array. i.e.., if the input is SSAD output should of SAD Synergy6
 
For more C Code Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com