structs

This is a discussion on structs within the C Programming forums, part of the General Programming Boards category; Am I somewhere wrong? Code: #include <stdio.h> #include <string.h> struct contacts { char fname[25]; char lname[25]; }; typedef struct contacts ...

  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    54

    structs

    Am I somewhere wrong?

    Code:
    #include <stdio.h>
    #include <string.h>
    
    
    struct contacts
    {
        char fname[25];
        char lname[25];
    };
    
    
    typedef struct contacts cont;
    
    
    int main(int argc, const char * argv[])
    {
        cont->fname[24] = '\0';
        cont->lname[24] = '\0';
        
        fgets(cont->fname, 23, stdin);
        puts(cont->fname);
        
        return 0;
    }

  2. #2
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Yes. cont is not an identifier ( a pointer to something ) it's a type.
    Kurt

  3. #3
    Registered User
    Join Date
    Dec 2012
    Posts
    54
    Oups.. Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 01-08-2013, 07:55 AM
  2. Typedef Structs inside Typdef structs
    By gremory in forum C Programming
    Replies: 21
    Last Post: 12-30-2011, 07:48 PM
  3. [ noob question ] Help with structs within structs
    By Riverfoot in forum C Programming
    Replies: 3
    Last Post: 04-26-2011, 08:24 PM
  4. Passing Structs Into An Array Of Structs.
    By TheTaoOfBill in forum C Programming
    Replies: 3
    Last Post: 10-07-2010, 10:38 AM
  5. passing structs & pointers to structs as arguments
    By Markallen85 in forum C Programming
    Replies: 6
    Last Post: 03-16-2004, 07:14 PM

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