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 / shruti

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 ?    32 Yes 28 No

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

Answer / yogesh

#include<stdio.h>
int main()
{
char str[80],str1[80];
int i,j;
printf("\n Enter String:");
fgets(str,80,stdin);
for(i=strlen(str)-1,j=0;i>=1;i--)
str1[j++]=str[i];
printf("Reversed String is:%s",str1);
}

Is This Answer Correct ?    18 Yes 14 No

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

Answer / savita chauhan

#include<stdio.h>
#include<conio.h>
int reverse(char *)
void main()
{
char a[];
int i,l;
clrscr();
printf("\n Enter the string");
gets(a);
l=reverse(a)-1;
printf("\n\n\n");
printf("\n Reverse is:");
while(l>=0)
{
printf("%c",a[l]);
l--;
}
getch();
}
int reverse(char *p);
{
int i=0;
while(*p!='\0')
{
i++;
p++;
}
return i;
}

Is This Answer Correct ?    10 Yes 6 No

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

Answer / amit soni

#include<stdio.h>
void main()
{
int i,j;
char a[10];
printf("Enter your string which you want to reverse");
gets(a);
for(i=0;a[i]!=NULL;i++);
for(j=i-1;j>=0;j--)
printf("%c",a[j]);
getch();
}

Is This Answer Correct ?    14 Yes 10 No

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

Answer / summit sehgal

char * rev(char * str)
{
char *str2; int n=0;
while (*str!='\0')
{
*(str2+n)=*(str(strlen(str))-n);
n++;
}
*str2='\0';
str=str2;
return(str);
}

Is This Answer Correct ?    4 Yes 0 No

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

Answer / muthu18.gs

void strrev(char *str)
{
int i;j=strlen(str),l;
l=j/2

for(i=0,j=j-1;i<=l;str[i]^=str[j]^=str[i++]^=str[j--]);
}

Is This Answer Correct ?    4 Yes 0 No

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

Answer / vivekanandan

#include<stdio.h>
#include<string.h>
#include<conio.h>
void main()
{
int len=0;
char str[100];
clrscr();
printf("\nEnter the string");
gets(str);
while(str[len]!='\0')
{
len++;
}
printf("\nThe Reverse of the string is");
for(int i=0;i<=len;i++)
{
printf("%c",str[len-i]);
}
getch();
}

Is This Answer Correct ?    5 Yes 1 No

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

Answer / neelu

#include<stdio.h>
#include<string.h>
main()
{
char a[10],b[10];
int i,l;
printf("enter the string to be reversed");
scanf("%s",a);
l=strlen(a);
for(i=0;i<l;i++)
b[i]=a[l-1-i];
b[i]='\0';
printf("%s",b);
}

Is This Answer Correct ?    4 Yes 0 No

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

Answer / abhijit s k

#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
char str[] = "test string";
char revstr[50];
int i=0,j;
printf("Original string is %s",str);
for(j = strlen(str) - 1;j>= 0;j --)
{

revstr[i] = str[j];
i++;
}
printf("\n Post reversal,string is %s",revstr);
return 0;
}

Is This Answer Correct ?    4 Yes 0 No

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

Answer / ken paul bahinting

#include<stdio.h>
#include<string.h>
main()
{
char a[10],b[10];
int i,l;
printf("enter the string to be reversed:");
gets(a);
l=strlen(a);
for(i=0;i<l;i++)
b[i]=a[l-1-i];
b[i]='\0';
printf("The reversed string is %s\n",b);
}

Is This Answer Correct ?    4 Yes 0 No

Post New Answer

More C Code Interview Questions

void main() { printf(“sizeof (void *) = %d \n“, sizeof( void *)); printf(“sizeof (int *) = %d \n”, sizeof(int *)); printf(“sizeof (double *) = %d \n”, sizeof(double *)); printf(“sizeof(struct unknown *) = %d \n”, sizeof(struct unknown *)); }

1 Answers  


main() { int y; scanf("%d",&y); // input given is 2000 if( (y%4==0 && y%100 != 0) || y%100 == 0 ) printf("%d is a leap year"); else printf("%d is not a leap year"); }

1 Answers  


main() { char *cptr,c; void *vptr,v; c=10; v=0; cptr=&c; vptr=&v; printf("%c%v",c,v); }

1 Answers  


main() { int c = 5; printf("%d", main||c); } a. 1 b. 5 c. 0 d. none of the above

2 Answers   HCL,


char *someFun1() { char temp[ ] = “string"; return temp; } char *someFun2() { char temp[ ] = {‘s’, ‘t’,’r’,’i’,’n’,’g’}; return temp; } int main() { puts(someFun1()); puts(someFun2()); }

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  


#include <stdio.h> int main(void) { int a=4, b=2; a=b<<a+b>>2 ; printf("%d",a); return 0; }

0 Answers   Student,


Write a Program in 'C' To Insert a Unique Number Only. (Hint: Just Like a Primary Key Numbers In Database.) Please Some One Suggest Me a Better Solution for This question ??

0 Answers   Home,


main() { 41printf("%p",main); }8

1 Answers  


void main() { char far *farther,*farthest; printf("%d..%d",sizeof(farther),sizeof(farthest)); }

2 Answers  


write a c-program to find gcd using recursive functions

5 Answers   HTC, Infotech,


Which version do you prefer of the following two, 1) printf(“%s”,str); // or the more curt one 2) printf(str);

1 Answers  


Categories