How to reverse a String without using C functions ?

Answers were Sorted based on User's Feedback



How to reverse a String without using C functions ?..

Answer / shiva

string Name = "12345";
char[] characters = Name.ToCharArray();
StringBuilder sb = new StringBuilder();
for (int i = Name.Length - 1; i >= 0; --i)
{
sb.Append(characters[i]);
}
Console.Write(sb.ToString());
Console.Read();

Is This Answer Correct ?    4 Yes 0 No

How to reverse a String without using C functions ?..

Answer / dhirendra kumar

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()

{
clrscr();
char a[30],ch[30];
int i,j,count=0,k=0;
printf("enter string in array\n");
gets(a);


for(i=0;a[i]!='\0';i++)
{
count++;
}
printf("length=%d\n",count);
printf("Reverse string===");
for(i=j;i>=0;i--)
{
putchar(a[i]);
}

getch();
}

Is This Answer Correct ?    3 Yes 2 No

How to reverse a String without using C functions ?..

Answer / sakshi pandey

#include<stdio.h>
#include<conio.h>
void main()
{
char str[6],item;
int i,len;
clrscr();
printf("enter a string:\n");
scanf("%s",&str);
len=strlen(len);
for(i=1;i<=len;i++)
{
item=str[i];
str[i]=str[len];
str[len--]=item;
}
printf("reverse string:%s",str);
getch();
}

Is This Answer Correct ?    12 Yes 12 No

How to reverse a String without using C functions ?..

Answer / vinod

char * rev_string (char * str)
{
char temp;
int i , j;
while(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 ?    3 Yes 3 No

How to reverse a String without using C functions ?..

Answer / dhiru

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()

{
clrscr();
char a[30],ch[30];
int i,j,count=0,k=0;
printf("enter string in array\n");
gets(a);

//j=strlen(a);
for(i=0;a[i]!='\0';i++)
{
count++;
}
printf("length=%d\n",count);
printf("Reverse string===");
for(i=count;i>=0;i--)
{
putchar(a[i]);
}

getch();
}

Is This Answer Correct ?    1 Yes 2 No

How to reverse a String without using C functions ?..

Answer / weqweqwe

void mstrreev(char * inStr)
{
if(*inStr!='\0')
{
return;
}
else
{
*/ mstrreev(++inStr);
}
putchar(*(--inStr));
}
void main(int argc, char* argv[])
{

mstrreev("Sushant");
}

Is This Answer Correct ?    0 Yes 3 No

How to reverse a String without using C functions ?..

Answer / abhishek gambhir

int l=0,i;
while(str[l]!='\0')
{
l++;
}
for(i=l-1;i>=0;i--)
{
cout<<str{i];
}

Is This Answer Correct ?    11 Yes 15 No

How to reverse a String without using C functions ?..

Answer / srinivas

#include<stdio.h>

void main()
{
char s[5]="srini";
char *p;
p=(char*)malloc(sizeof(char)*5);
while((*p++=s[--strlen(s)])!='\0');
*p='\0';
printf("%s",p);
}

Is This Answer Correct ?    6 Yes 10 No

How to reverse a String without using C functions ?..

Answer / kalpana

#include<stdio.h>

void reverse( const char * const sPtr );

int main(){
char sentence[ 80 ];

printf( "Enter a line of text:\n" );
gets( sentence );

printf( "\nThe line printed backwards is:\n" );
reverse( sentence );
}

void reverse( const char * const sPtr ){
if( sPtr[ 0 ] == '\0' ){
return;
}
else{
reverse( &sPtr[ 1 ] );

putchar( sPtr[ 0 ] );
}
}

Is This Answer Correct ?    5 Yes 10 No

How to reverse a String without using C functions ?..

Answer / sushamaa

/*The program to reverse the given input string*/

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

void main()
{
char str[20];
int i=0,a,b;
clrscr();

printf("\nEnter the given string:");
scanf("%s",str);

do
{
a=str[i];
i++;
}while(a!=0);

i=i-1;
printf("\nThe reverse string:");

do
{
b=str[i];
printf("%c",b);
i--;
}while(i>=0);

getch();

Is This Answer Correct ?    9 Yes 17 No

Post New Answer

More C Code Interview Questions

write a program to find out roots of quadratic equation "x=-b+-(b^2-4ac0^-1/2/2a"

2 Answers  


#include<conio.h> main() { int x,y=2,z,a; if(x=y%2) z=2; a=2; printf("%d %d ",z,x); }

1 Answers  


main() { char *p="hai friends",*p1; p1=p; while(*p!='\0') ++*p++; printf("%s %s",p,p1); }

3 Answers  


write a c program to Create a mail account by taking the username, password, confirm password, secret_question, secret_answer and phone number. Allow users to register, login and reset password(based on secret question). Display the user accounts and their details .

2 Answers  


Question: We would like to design and implement a programming solution to the reader-writer problem using semaphores in C language under UNIX. We assume that we have three readers and two writers processes that would run concurrently. A writer is to update (write) into one memory location (let’s say a variable of type integer named temp initialized to 0). In the other hand, a reader is to read the content of temp and display its content on the screen in a formatted output. One writer can access the shared data exclusively without the presence of other writer or any reader, whereas, a reader may access the shared memory for reading with the presence of other readers (but not writers).

1 Answers  






# include<stdio.h> aaa() { printf("hi"); } bbb(){ printf("hello"); } ccc(){ printf("bye"); } main() { int (*ptr[3])(); ptr[0]=aaa; ptr[1]=bbb; ptr[2]=ccc; ptr[2](); }

1 Answers  


Ramesh’s basic salary is input through the keyboard. His dearness allowance is 40% of basic salary, and house rent allowance is 20% of basic salary. Write a program to calculate his gross salary.

1 Answers  


#include<stdio.h> void fun(int); int main() { int a; a=3; fun(a); printf("\n"); return 0; } void fun(int i) { if(n>0) { fun(--n); printf("%d",n); fun(--n); } } the answer is 0 1 2 0..someone explain how the code is executed..?

1 Answers   Wipro,


1) int i=5; j=i++ + i++ + i++; printf("%d",j);This code gives the answer 15.But if we replace the value of the j then anser is different?why? 2)int i=5; printf("%d",i++ + i++ + i++); this givs 18.

8 Answers   IBPS, Infosys, TCS,


Given an array of size N in which every number is between 1 and N, determine if there are any duplicates in it. You are allowed to destroy the array if you like.

21 Answers   ABC, eBay, Goldman Sachs, Google, HUP, Microsoft, TATA,


All the combinations of prime numbers whose sum gives 32

1 Answers   HHH,


char inputString[100] = {0}; To get string input from the keyboard which one of the following is better? 1) gets(inputString) 2) fgets(inputString, sizeof(inputString), fp)

1 Answers  


Categories