How do you swap strings?

Glenn Ford glenn at zeus.ocs.com
Wed Jun 5 03:18:21 AEST 1991


In article <1991Jun1.203738.28387 at jack.sns.com> jtanner at 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 at zeus.ocs.com
..uunet!ocsmd!glenn




More information about the Comp.lang.c mailing list