Re: [algogeeks] String Swapping Problem

2011-06-16 Thread Apoorve Mohan
@sharma: dis has been explained to tiwari...ask him...:) On Fri, Jun 17, 2011 at 3:12 AM, DIPANKAR DUTTA wrote: > instead of calling swap(&ps[0],&ps[1]) can u try with swap(ps[0],ps[1]) or > swap(&ps[0][0],&ps[1][0]) ? > > On Fri, Jun 17, 2011 at 5:05 AM, udit sharma wrote: > >> #includevoid swap

Re: [algogeeks] String Swapping Problem

2011-06-16 Thread Rohit Sindhu
#include void swap(char **p,char **q) { char *t; t=*p; *p=*q; *q=t; } int main(){ char *ps[2]={ "Hello", "Good Morning", }; swap( &ps[0] , &ps[1]); printf("%s \t %s\n",ps[0],ps[1]); return 0; } This one breaks the ice ... as you have to change the contents of the array wh

Re: [algogeeks] String Swapping Problem

2011-06-16 Thread Rohit Sindhu
The function swap just swaps it's local copy of pointers which does not mean that it swap array elements. You have to do it explicitly. On Fri, Jun 17, 2011 at 3:17 AM, udit sharma wrote: > Ohh Sry... The qus was: > > >> #includevoid swap(char *,char *);int main(){char *ps[2]={ >>>

Re: [algogeeks] String Swapping Problem

2011-06-16 Thread udit sharma
Ohh Sry... The qus was: > #includevoid swap(char *,char *);int main(){char *ps[2]={ >> "Hello", >> "Good Mornning", >> };swap(ps[0],ps[1]);printf("%s \t %s\n",ps[0],ps[1]);return 0;} >> void swap(char *p,char *q){char *t;t=p;p=q;q=t;} >> >> >> why the output is: >>

Re: [algogeeks] String Swapping Problem

2011-06-16 Thread DIPANKAR DUTTA
instead of calling swap(&ps[0],&ps[1]) can u try with swap(ps[0],ps[1]) or swap(&ps[0][0],&ps[1][0]) ? On Fri, Jun 17, 2011 at 5:05 AM, udit sharma wrote: > #includevoid swap(char *,char *);int main(){char *ps[2]={ > "Hello", > "Good Mornning", > };swap(&ps[0],&p

[algogeeks] String Swapping Problem

2011-06-16 Thread udit sharma
#includevoid swap(char *,char *);int main(){char *ps[2]={ "Hello", "Good Mornning", };swap(&ps[0],&ps[1]);printf("%s \t %s\n",ps[0],ps[1]);return 0;} void swap(char *p,char *q){char *t;t=p;p=q;q=t;} why the output is: HelloGood Mornning -- Regar