write function to reverse char array ... without using second
array

Answers were Sorted based on User's Feedback



write function to reverse char array ... without using second array..

Answer / nagesh r. dalave

void main()
{
char strp20];
int len=0,i=0;
printf("\nEnter a string ");
gets(str);
while(str[i]!='\0')
{
i++;
len++;
}
printf("\nReverse of given string:");
while(i>=0)
{
printf("\n %c",str[i]);
i--;
}
getch();
}

Is This Answer Correct ?    3 Yes 0 No

write function to reverse char array ... without using second array..

Answer / kiran

{
char temp;
for(i,j=strlen(str)-1;i<j;i++,j--)
{
temp = str[i];
str[i] = str[j];
str[j] = temp;
}
return str;
}

Is This Answer Correct ?    0 Yes 0 No

write function to reverse char array ... without using second array..

Answer / sunitha

/* function to reverse a charactor array */

void rev_array(char str[])
{
char c;
char *p;
p=str;
while(*p)
{
if(*p!='\0')
{
c=p;
}
p++;
}
printf("reverse array is %s\n",c);
}

Is This Answer Correct ?    1 Yes 7 No

Post New Answer

More C Interview Questions

Write a C program to read the internal test marks of 25 students in a class and show the number of students who have scored more than 50% in the test. Make necessary assumptions.

1 Answers  


difference between native and cross compilers

0 Answers  


How can I check whether a file exists? I want to warn the user if a requested input file is missing.

0 Answers  


What are the advantages of c preprocessor?

0 Answers  


What are the differences between new and malloc in C?

0 Answers   Amazon,






How to convert decimal to binary in C using recursion??

4 Answers   HP, IBM,


When should you not use a type cast?

0 Answers  


how to convert binary to decimal and decimal to binary in C lanaguage

7 Answers   BPO, Far East Promotions, IBM, RBS,


Which of the following is not an infinite loop ? a.while(1){ .... } b.for(;;){ ... } c.x=0; do{ /*x unaltered within theloop*/ ... }while(x==0); d.# define TRUE 0 ... while(TRUE){ .... }

7 Answers   TCS,


How to write a code for implementing my own printf() and scanf().... Please hep me in this... I need a guidance... Can you give an coding for c... Please also explain about the header files used other than #include<stdio.h>...

0 Answers  


int n=1; while(1) { switch(n) { case 1:printf("a"); n++; continue; case 2:printf("b"); n++; continue; default : printf("c"); break; } break; }

1 Answers  


What is the function of volatile in c language?

0 Answers  


Categories