Thread: HOWTO swap sturct or union?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    77

    HOWTO swap sturct or union?

    sturct or union is given. how to swap it? exchange each data???
    Code:
    #include <stdio.h>
    typedef struct {
    	int k;
    	int s;
    	int f;
    }sfType;
    
    void exchange(int *x, int *y)
    {
    	int t = *x;
    	*x = *y;
    	*y = t;
    }
    
    void exchangeSF(sfType *sf1, sfType *sf2)
    {
    	exchange(&sf1.k, &sf2.k);
    	exchange(&sf1.s, &sf2.s);
    	exchange(&sf1.f, &sf2.f);
    }
    ...........
    int main()
    {.........}
    GCC said that It wasn't a structure or union in exchange(&sf1.k, &sf2.k), exchange(&sf1.s, &sf2.s) and exchange(&sf1.f &sf2.f);
    Last edited by Mathsniper; 06-10-2005 at 08:13 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sizeof union question
    By noops in forum C Programming
    Replies: 13
    Last Post: 06-06-2008, 11:56 AM
  2. Replies: 16
    Last Post: 10-29-2006, 05:04 AM
  3. "generic" union or something
    By Raven Arkadon in forum C++ Programming
    Replies: 2
    Last Post: 12-05-2005, 09:55 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Sorting a Union
    By andy in forum C Programming
    Replies: 4
    Last Post: 11-21-2001, 10:12 AM