structure question

This is a discussion on structure question within the C Programming forums, part of the General Programming Boards category; EDIT: whats wrong with my structure?, i always do it like this, but i get errors this time Code: #include ...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    266

    structure question

    EDIT:
    whats wrong with my structure?, i always do it like this, but i get errors this time

    Code:
    #include <stdio.h>
    
      
    struct rec
    {
    int age,id=0;
    char name[31];
    
    };
    
    
    int main(){
    
    char iuser[31];
    int c=0;
    int input;
    
    
    }
    Last edited by rodrigorules; 09-20-2005 at 09:01 AM.

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,162
    Code:
    int age,id=0;
    You can't initialize a variable inside a struct definition. I really doubt you always do it that way. Also, next time it would be nice if you actually included the error message you get including the line number.
    Last edited by itsme86; 09-20-2005 at 09:19 AM.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    135
    Quote Originally Posted by rodrigorules
    EDIT:
    whats wrong with my structure?, i always do it like this, but i get errors this time

    Code:
    #include <stdio.h>
    
      
    struct rec
    {
    int age,id=0;
    char name[31];
    
    };
    
    
    int main(){
    
    char iuser[31];
    int c=0;
    int input;
    }
    If you want to initialize a struture when you define it, you can do this:


    Code:
    struct rec
    {
    int age,id=0;
    char name[31];
    } recVar = {0, 0, "string"};
    first two zeros are for, age and id. "string" is for, name.

    OR...

    During declaration:
    Code:
    struct rec recVar = {0, 0, "string"};

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    266
    ya thanks eddie, learned something new

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 13
    Last Post: 12-14-2007, 02:34 PM
  2. Simple C# structure question
    By sketch in forum C# Programming
    Replies: 4
    Last Post: 09-14-2007, 04:29 PM
  3. data structure question
    By miami_victor in forum C++ Programming
    Replies: 13
    Last Post: 12-30-2004, 11:56 PM
  4. Array and Structure Question
    By loopshot in forum C++ Programming
    Replies: 2
    Last Post: 10-21-2004, 05:10 PM
  5. structure question
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 12-03-2001, 08:04 PM

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