#include<stdio.h> #include<error.h> #include<malloc.h> #include<stdlib.h> void swap(void *p1,void *p2,const unsigned size) { char *buff=(char*) malloc(size*sizeof(char)); if(!buff) { perror("malloc"); exit(11); } memcpy(buff,p1,size); memcpy(p1,p2,size); memcpy(p2,buff,size); free(buff); return; } int main() { int a=12,b=24; char c='a',d='b'; float e=1.1f,f=2.3f; char wrd1[]="Hello"; char wrd2[]="Bye"; char *p=wrd1; char *q=wrd2; swap(&a,&b,sizeof(int)); swap(&c,&d,sizeof(char)); swap(&e,&f,sizeof(float)); swap(&p,&q,sizeof(p)); printf("%d\t%d\n",a,b); printf("%c\t%c\n",c,d); printf("%f\t%f\n",e,f); printf("%s\t%s\n",p,q); return 0; } Its a generic function not a macro, I know but the idea would be same.
-- Saurabh Singh B.Tech (Computer Science) MNNIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.