Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8988897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:07:22+00:00 2026-06-15T22:07:22+00:00

say a struct like this: typedef struct testVertex_s { char *vert_name; //for test only…

  • 0

say a struct like this:

typedef struct testVertex_s {
       char *vert_name; //for test only...
       float x;
       float y;
       float z;
}testvertex_t;

how to write that to a binary file use python ? I want to read it using fread in c;

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:07:23+00:00Added an answer on June 15, 2026 at 10:07 pm

    Why must it be binary? Text is trivial, and much simpler to interact with.

    If you really want binary, use the struct module. Make sure to define your endianness, and read each field separately in C, do not try to do a single fread() into a C structure.

    You could do the packing like so:

    import struct
    out = open("myvertex.bin", "wb")
    string = "hello"
    fmt = "<%usfff" % (1 + len(string))
    out.write(struct.pack(fmt, string, 3.14, 47.11, 17))
    

    This writes the string as a plain 0-terminated string, followed immediately by the floats. The resulting data from the above is "hello\x00\xc3\xf5H@\xa4p<B\x00\x00\x88A" (represented as a Python string literal).

    For this case, you’re going to need to dynamically allocate the string of course, which should be obvious.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a first structure like this: typedef struct { int ivalue;
Say I have a struct that looks like this (a POD): struct Foo {
Let's say I have this struct in ANSI C: typedef struct _point { float
Say I have a struct like the following ... typedef struct { int WheelCount;
Suppose there is CGo package with a struct defined like this: package test ...
I want to convert this C++ code to C#: typedef struct consoleCommand_s { char*
Let's say I have a class like this: class LinkedList { struct Node {
Say the structure for the file I want to read looks like this: typedef
Say I have some structs like this: struct A{ int someInt; } struct B
I am using a 3rd party library that has a declaration like this: typedef

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.