Thread: what does this typedef line..

  1. #1
    Banned
    Join Date
    Oct 2008
    Posts
    1,535

    what does this typedef line..

    first i create this structure :

    Code:
    struct album { 
      char *name; 
      char *artist; 
      int numTracks; 
    }
    if i want my variables not to be global
    i can write this inside main:

    struct album CD1, CD2, CD3;

    or
    "
    typedef struct album Album;

    ... then inside main:

    Album CD1, CD2, CD3;
    "

    i cant understand this last part regarding where to write the typedef line

    and what is the role of type of typedef?

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    typedef creates an alias for a type. so you can do

    struct album CD1, CD2, CD3;

    or you can do

    Album CD1, CD2, CD3;

    Both mean the same thing.

  3. #3
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    thanks

  4. #4
    Registered User
    Join Date
    Oct 2008
    Location
    vizag
    Posts
    2
    first put a ; after the structure ends and after that function declaration and then typedef the structure then write main

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error: redefinition of typedef xxxx
    By Rocha in forum C Programming
    Replies: 2
    Last Post: 11-24-2008, 09:19 AM
  2. adding line numbers and concatenating a filename
    By durrty in forum C Programming
    Replies: 25
    Last Post: 06-28-2008, 03:36 AM
  3. Need help understanding info in a header file
    By hicpics in forum C Programming
    Replies: 8
    Last Post: 12-02-2005, 12:36 PM
  4. Trouble replacing line of file
    By Rpog in forum C Programming
    Replies: 4
    Last Post: 04-19-2004, 10:22 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM