Thread: Global structure def's

  1. #1
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257

    Global structure def's

    For some reason C doesn't like a global structure definition. I have it set up like this:
    Code:
    struct EDFSection
    {
    	char Param[20];
    	int Label, SFactor, SigBits;
    	int Bit30, Bit31;
    } ;
    
    int 
    main (void)
    {
    	
    	EDFSection Sec;
    ........
    Sec.Param = Temp[1];
    		Sec.Label = atoi(Temp[2]);
    		Sec.SFactor = atoi(Temp[3]);
    		Sec.SigBits = atoi(Temp[4]);
    		Sec.Bit31 = atoi(Temp[5]);
    		Sec.Bit30 = atoi(Temp[6]);
    The array Temp contains strings of a fixed length. I tried writing a function to print the structure, as outlined in FAQ > Prelude's Corner > All about structures
    But it won't cooperate.
    Here's the function:
    Code:
    void print_Struct ( struct EDFSection sec )
    {
      printf ( "%s\t", sec.Param);
      printf ( "%d\t", sec.Label );
      printf ( "%d\t", sec.SFactor );
      printf ( "%d\t", sec.SigBits );
      printf ( "%d\t", sec.Bit31);
      printf ( "%d\t", sec.Bit30 );
    }
    Even declaring the structure inside the main function didn't work. What's missing?

  2. #2
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257
    Sorry forgot. Here's the error message that I get;
    Code:
    : error C2065: 'EDFSection' : undeclared identifier
    H:\Code\Parse EDF\main FN.c(17) : error C2146: syntax error : missing ';' before identifier 'Sec'
    H:\Code\Parse EDF\main FN.c(17) : error C2065: 'Sec' : undeclared identifier
    H:\Code\Parse EDF\main FN.c(56) : error C2224: left of '.Param' must have struct/union type
    H:\Code\Parse EDF\main FN.c(57) : error C2224: left of '.Label' must have struct/union type
    H:\Code\Parse EDF\main FN.c(58) : error C2224: left of '.SFactor' must have struct/union type
    and the same for each time I use Sec. ...

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    In C, use the struct keyword.
    Code:
    	struct EDFSection Sec;
    [edit]If this is related to your previous thread, you can use %d with sscanf and avoid the atoi.
    Last edited by Dave_Sinkula; 06-14-2005 at 08:50 AM.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257
    Thanks, that works. Obviously; why would you tell me something that won't work .

    A.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Global Structure question.
    By tdep in forum C Programming
    Replies: 6
    Last Post: 07-04-2007, 05:59 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Global Structure
    By computerfreaks in forum C Programming
    Replies: 8
    Last Post: 02-18-2005, 01:59 PM
  4. Problems with Global Structure
    By bijju_savan in forum C Programming
    Replies: 1
    Last Post: 04-21-2002, 03:37 PM
  5. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM