Typedef understanding

This is a discussion on Typedef understanding within the C Programming forums, part of the General Programming Boards category; in my tutrial a shorthand version for structure like you could do in a program like ? Code: #include <stdio.h> ...

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    183

    Typedef understanding

    in my tutrial a shorthand version for structure like you could do in a program
    like ?
    Code:
    #include <stdio.h>
    typedef struct employee char address[50];
    int main(void)
    {
    struct employee emp;
    printf("Name is %s",emp.adress);
    return 0;
    }
    thanks in advanced for your help.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Yeah, that's a pretty horrible example. Do you have a question about why it doesn't work, or what?

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,304
    More like:
    Code:
    #include <stdio.h>
    
    typedef struct
    {
        char address[50];
    } employee;
    
    int main(void)
    {
        employee emp;
    
        /* Initialise emp */
    
        printf("Name is &#37;s", emp.address);
        return 0;
    }
    Of course, the struct could also be named.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    Dec 2008
    Posts
    183
    yes thanks laserswitch i understand it now its just
    a shortcut in way to not like struct employee variable you just do
    typedef struct employee thenyourshortcut.

  5. #5
    Registered User
    Join Date
    Dec 2008
    Posts
    183
    i tried this code
    Code:
    #include <stdio.h>
    struct employee
    {
    char name[50];
    char address[51];
    int age;
    float salary;
    };
    typedef struct employee shortcut;
    int main(void)
    {
    shortcut x;
    fputs("Please Enter your age: ",stdout);
    scanf("&#37;d",x.age);
    printf("Age is %d",x.age);
    fputs("Please Enter your salary: ",stdout);
    scanf("%f",x.salary);
    printf("Age is %f",x.salary);
    return 0;
    }
    but program crashed i dunt know why though.

  6. #6
    Registered User
    Join Date
    Dec 2008
    Posts
    183
    nvm lol i was too fast i forgot refressing it though lol & behind scanf variable
    Code:
     
    #include <stdio.h>
    struct employee
    {
    char name[50];
    char address[51];
    int age;
    float salary;
    };
    typedef struct employee shortcut;
    int main(void)
    {
    shortcut x;
    fputs("Please Enter your age: ",stdout);
    scanf("&#37;d",&x.age);
    printf("Age is %d",x.age);
    fputs("Please Enter your salary: ",stdout);
    scanf("%f",&x.salary);
    printf("Age is %f",x.salary);
    return 0;
    }

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,852
    Indentation - learn how to do it please!
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 09:18 PM
  2. Need help understanding info in a header file
    By hicpics in forum C Programming
    Replies: 8
    Last Post: 12-02-2005, 12:36 PM
  3. Please STICKY this- vital to MSVC 6 dev - BASETSD.h
    By VirtualAce in forum Game Programming
    Replies: 11
    Last Post: 03-15-2005, 09:22 AM
  4. build errors migrated from dx9b to dx9c sdk
    By reanimated in forum Game Programming
    Replies: 4
    Last Post: 12-17-2004, 07:35 AM
  5. oh me oh my hash maps up the wazoo
    By DarkDays in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 12:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21