Thread: C struct

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    2

    Talking C struct

    im new and know how to make a struct in C++ but how do i make one in C?

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    32
    Code:
    struct person {
        int age;
        char *name;
    };
    
    .....
    struct person me;
    me.age = 16;
    me.name = "serruya"; //use strcpy of course :P
    You can use typedef's to create new variables types...

  3. #3
    Registered User
    Join Date
    May 2003
    Posts
    2
    hmm on the tutorial they said it was different in C

    edit: oh... i see in C you put> struct structname identifier
    Last edited by Mukunda51; 05-07-2003 at 07:27 AM.

  4. #4
    Registered User
    Join Date
    May 2003
    Posts
    5

    Wink struct

    struct struct_tag {
    data_type1 variable1;
    data_type2 variable2;
    data_type3 variable3;
    ...
    };
    it seems the same as C++

  5. #5
    Registered User
    Join Date
    May 2003
    Posts
    2
    It is done in the same manner as in C++. The creation policy in C++ is more so replication of C++. Th whole concept in C++ is to have classess, structs were there just to add backward compatibilty to the C++ system.

    So if u know structs in C++, u know the most of structs in C, except finer tweaks like there are no classifies like privae, public.
    No functions can be a part of struct

    Code:
    struct anything{
             int anyone;
             char anyday[100];
            } done;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 12-03-2008, 03:10 AM
  2. Global Variables
    By Taka in forum C Programming
    Replies: 34
    Last Post: 11-02-2007, 03:25 AM
  3. Replies: 10
    Last Post: 05-18-2006, 11:23 PM
  4. What's wrong with my search program?
    By sherwi in forum C Programming
    Replies: 5
    Last Post: 04-28-2006, 09:57 AM
  5. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 09:40 PM