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 |
int aaa() {printf(“Hi”);} int bbb(){printf(“hello”);} iny ccc(){printf(“bye”);} main() { int ( * ptr[3]) (); ptr[0] = aaa; ptr[1] = bbb; ptr[2] =ccc; ptr[2](); }
main() { int i = 258; int *iPtr = &i; printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) ); }
In a gymnastic competition, scoring is based on the average of all scores given by the judges excluding the maximum and minimum scores. Let the user input the number of judges, after that, input the scores from the judges. Output the average score. Note: In case, more than two judges give the same score and it happens that score is the maximum or minimum then just eliminate two scores. For example, if the number of judges is 5 and all of them give 10 points each. Then the maximum and minimum score is 10. So the computation would be 10+10+10, this time. The output should be 10 because 30/3 is 10.
Print an integer using only putchar. Try doing it without using extra storage.
main() { char *p="GOOD"; char a[ ]="GOOD"; printf("\n sizeof(p) = %d, sizeof(*p) = %d, strlen(p) = %d", sizeof(p), sizeof(*p), strlen(p)); printf("\n sizeof(a) = %d, strlen(a) = %d", sizeof(a), strlen(a)); }
Write a C program to print look and say sequence? For example if u get the input as 1 then the sequence is 11 21 1211 111221 312211 12112221 .......(it counts the no. of 1s,2s etc which is in successive order) and this sequence is used in run-length encoding.
create a login program that ask username and password. if you input username or password 3 times wrong, the program will terminate else the program will prompt a message "congratulations"
write a c program to Create employee record by taking details like name, employee id, address and phone number. While taking the phone number, take either landline or mobile number. Ensure that the phone numbers of the employee are unique. Also display all the details
Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal.
6 Answers Fusion Systems GmbH,
Write a C program to print ‘Campus Force training’ without using even a single semicolon in the program.
main() { printf("%d, %d", sizeof('c'), sizeof(100)); } a. 2, 2 b. 2, 100 c. 4, 100 d. 4, 4
18 Answers HCL, IBM, Infosys, LG Soft, Satyam,
struct Foo { char *pName; }; main() { struct Foo *obj = malloc(sizeof(struct Foo)); clrscr(); strcpy(obj->pName,"Your Name"); printf("%s", obj->pName); } a. Your Name b. compile error c. Name d. Runtime error