How to reverse a String without using C functions ?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 *)); }
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"); }
main() { char *cptr,c; void *vptr,v; c=10; v=0; cptr=&c; vptr=&v; printf("%c%v",c,v); }
main() { int c = 5; printf("%d", main||c); } a. 1 b. 5 c. 0 d. none of the above
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()); }
#include<conio.h> main() { int x,y=2,z,a; if(x=y%2) z=2; a=2; printf("%d %d ",z,x); }
#include <stdio.h> int main(void) { int a=4, b=2; a=b<<a+b>>2 ; printf("%d",a); return 0; }
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 ??
main() { 41printf("%p",main); }8
void main() { char far *farther,*farthest; printf("%d..%d",sizeof(farther),sizeof(farthest)); }
write a c-program to find gcd using recursive functions
Which version do you prefer of the following two, 1) printf(“%s”,str); // or the more curt one 2) printf(str);