my mistake,
for 2)you cant change the address of the any array,(use change it to
char *t1="xyz",*t2="abc"; )
i thought pstr is array of array of strings(but is array of character
pointer),
@sachindraac is right
char *pstr[2] = {"Hello", "piyush"};
Thank you,
Sid.
On Wed, Sep 7, 2011 at 11:34 AM, Shachindra A C <[email protected]> wrote:
>
> I assume you expect to see the strings interchanged. But you are not changing
> anything in the memory. So in main(), pstr[0] and pstr[1] contains whatever
> was there earlier. If you change the parameters of the swap to swap(char
> **,char **), pass the addresses of pstr[0] ,pstr[1] and then do whatever u r
> doing in swap, the strings will get exchanged.
>
> On Wed, Sep 7, 2011 at 11:26 AM, piyush agarwal <[email protected]> wrote:
>>
>> #include<stdio.h>
>> void swap(char *, char *);
>>
>> int main()
>> {
>> char *pstr[2] = {"Hello", "piyush"};
>> swap(pstr[0], pstr[1]);
>> printf("%s\n%s", pstr[0], pstr[1]);
>> return 0;
>> }
>> void swap(char *t1, char *t2)
>> {
>> char *t;
>> t=t1;
>> t1=t2;
>> t2=t;
>> }
>>
>>
>> --
>> Piyush Agarwal
>> Final Year Undergraduate
>> Department of Computer Engineering
>> Malaviya National Institute of Technology
>> Jaipur
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>
>
>
> --
> Regards,
> Shachindra A C
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.