help me with C codes

This is a discussion on help me with C codes within the C Programming forums, part of the General Programming Boards category; I have the following struct defined: Code: typedef struct FrameHdr { u_char type; /* SSWP_DATA or SSWP_ACK */ SeqNum seq; ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    569

    help me with C codes

    I have the following struct defined:

    Code:
    typedef struct FrameHdr {
        u_char	type;		/* SSWP_DATA or SSWP_ACK */
        SeqNum	seq;		/* sequence number */
        u_char	size;		/* size of payload */
        u_char	flags;		/* see below */
    } FrameHdr;
    
    
    typedef struct Frame {
        FrameHdr	hdr;		/* Frame header */
        u_char	body[256];	/* Body */
    } Frame;
    and in my .c file I have the following:

    Code:
    Frame frame;
    frame.hdr.size = ....;
    frame.hdr.type = ....;
    frame.hdr.seq = ....;
    however I got these errors:

    sender.c:180: error: ‚FrameHdr‚ has no member named ‚type‚
    sender.c:181: error: ‚FrameHdr‚ has no member named ‚seq‚
    sender.c:181: error: ‚FrameHdr‚ has no member named ‚size‚

    what am I doing wrong here?

  2. #2
    Registered User carrotcake1029's Avatar
    Join Date
    Apr 2008
    Posts
    398
    Looks fine to me. Are you sure that the structs you have shown are within the scope of the function you are trying to work with?

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    the structs are declared on another .h file which I already included in the header of the .c file,. I also tried the following alternative, but it doesn't work as well

    Code:
    Frame* frame = (Frame*) malloc(sizeof(Frame));
    frame->hdr->type = TYPE_DATA;
    frame->hdr->seq = (SeqNum) LFS;
    frame->hdr->size = 0;

  4. #4
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    check the header guards - that they are unique in each homemade header

    if headers are from some library - check maybe some defines are needed, that will modify FrameHdr definition
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. codes
    By IfYouSaySo in forum A Brief History of Cprogramming.com
    Replies: 34
    Last Post: 11-18-2005, 03:09 PM
  2. Replies: 1
    Last Post: 07-12-2005, 10:03 PM
  3. action replay codes
    By c++.prog.newbie in forum Game Programming
    Replies: 2
    Last Post: 02-28-2004, 08:47 AM
  4. anyone have linked-list sample codes?
    By ling in forum C++ Programming
    Replies: 3
    Last Post: 07-03-2002, 03:24 PM

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