Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uunet!ocsmd!zeus!glenn From: glenn@zeus.ocs.com (Glenn Ford) Newsgroups: comp.lang.c Subject: Re: How do you swap strings? Message-ID: <1226@ocsmd.com> Date: 4 Jun 91 17:18:21 GMT References: <1991Jun1.203738.28387@jack.sns.com> Sender: news@ocsmd.com Distribution: na Organization: Online Computer Systems, Germantown MD Lines: 31 In article <1991Jun1.203738.28387@jack.sns.com> jtanner@jack.sns.com (Jason Tanner) writes: > > Is there a command to swap to elements in an array? >Currently I am using strcpy and a temporary string to swap around the 2 >elements and this dosnt seem to work very well.. Swapping strings is >such an important command I cant believe that it dosnt exist.. now I am using >something like this.. > > strcpy(temp,destination); > strcpy(destination,source); > strcpy(source,temp); > not good, especially if used alot. add this: char *ptr_temp; char *ptr_dest; char *ptr_source; ptr_temp = ptr_dest; ptr_dest = ptr_source; ptr_source = ptr_temp; working with pointers to strings is MUCH faster than using just a regular string. Especially for string manipulation.. Glenn Ford glenn@zeus.ocs.com ..uunet!ocsmd!glenn