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

What is strcmp in c?

0 Answers  


please tell me the logic for this C program : INPUT (string):ABCD OUTPUT :BCDA CDAB DABC

2 Answers   Mphasis,


What are different storage class specifiers in c?

0 Answers  


What does a derived class inherit from a base class a) Only the Public members of the base class b) Only the Protected members of the base class c) Both the Public and the Protected members of the base class d) .c file

0 Answers  


How can I change their mode to binary?

0 Answers  






what is the difference between exit() and _exit() functions?

2 Answers  


What is void main () in c?

0 Answers  


Which one to choose from 'initialization lists' or 'assignment', for the use in the constructor?

0 Answers  


What are the advantages of external class?

0 Answers  


change to postfix a/(b+c*d-e)

8 Answers   Value Labs,


What is a macro?

0 Answers  


Explain what is a 'null pointer assignment' error? Explain what are bus errors, memory faults, and core dumps?

0 Answers  


Categories