Thread: Issue with Structs

  1. #31
    Registered User
    Join Date
    Mar 2008
    Posts
    25
    Surely I can't use sizeof(message) though...

    That's going to be 4 bytes wihch is wrong as the message could be up to 300 bytes long...

  2. #32
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Yes, this is true. But I'm not sure what the solution iMalc had in mind is.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #33
    Registered User
    Join Date
    Mar 2008
    Posts
    25
    The way it stands I have little choice as the program I'm communicating with is already made and cannot be changed.

    I need to send one buffer in the form:

    [<- 12 bytes of header->][<- variable length up to 64 bytes - of options->][-< variable length up to 300 bytes - of message->]

    There's no way to change that.

    I doubt sending the sizeof(options) (= 64) is a good plan, because it will expect 64 bytes of options probably. Most of the time only the first 2 elements of the array are set.

  4. #34
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Then make it fixed.
    Use 12 bytes, 64 bytes and then 300 bytes.
    No hassle with size and it will be easy to gut the data when received at the other end.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #35
    Registered User
    Join Date
    Mar 2008
    Posts
    25
    Can you explain what you mean please?

    Thanks.

  6. #36
    Registered User
    Join Date
    Mar 2008
    Posts
    25
    Actually, I think I will make it so that the message is no longer passed in as an argument and I could just get the message inside the function and that way, both options and message will be local arrays inside the function and I will be able to sue sizeof without any problems.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating array of structs
    By knirirr in forum C++ Programming
    Replies: 12
    Last Post: 06-18-2008, 08:30 AM
  2. Multidimentional structs + memcpy() == FAIL
    By Viper187 in forum C Programming
    Replies: 8
    Last Post: 06-18-2008, 02:46 AM
  3. float calculation issue
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 05-26-2008, 04:56 AM
  4. ArrayLists + Inner Structs
    By ginoitalo in forum C# Programming
    Replies: 5
    Last Post: 05-09-2002, 05:09 AM
  5. Searching structs...
    By Sebastiani in forum C Programming
    Replies: 1
    Last Post: 08-25-2001, 12:38 PM