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 |
main() { char *p = “ayqm”; printf(“%c”,++*(p++)); }
29 Answers IBM, TCS, UGC NET, Wipro,
pls anyone can help me to write a code to print the values in words for any value.Example:1034 to print as "one thousand and thirty four only"
main() { int c[ ]={2.8,3.4,4,6.7,5}; int j,*p=c,*q=c; for(j=0;j<5;j++) { printf(" %d ",*c); ++q; } for(j=0;j<5;j++){ printf(" %d ",*p); ++p; } }
int a = 10 + 10 .... ,... A = A * A What would be the value of A? The answer is 120!! Could anyone explain this to me.
2 Answers Bosch, eInfochips, HCL, IHCL,
main() { extern i; printf("%d\n",i); { int i=20; printf("%d\n",i); } }
#include<stdio.h> main() { char s[]={'a','b','c','\n','c','\0'}; char *p,*str,*str1; p=&s[3]; str=p; str1=s; printf("%d",++*p + ++*str1-32); }
Implement a t9 mobile dictionary. (Give code with explanation )
1 Answers Amazon, Peak6, Yahoo,
#define FALSE -1 #define TRUE 1 #define NULL 0 main() { if(NULL) puts("NULL"); else if(FALSE) puts("TRUE"); else puts("FALSE"); }
Sorting entire link list using selection sort and insertion sort and calculating their time complexity
1 Answers Infosys, Microsoft, NetApp,
# 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](); }
Find the largest number in a binary tree
Declare an array of N pointers to functions returning pointers to functions returning pointers to characters?