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 6384171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:44:32+00:00 2026-05-25T02:44:32+00:00

I need to fwrite a char * to file and fread it on another

  • 0

I need to fwritea char * to file and fread it on another platform where char‘s signedness varies.

  • Are there ways to solve this other than explicitly serializing a unsigned char*?
  • Is it always safe to cast a char* to an unsigned char*?
  • 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-05-25T02:44:33+00:00Added an answer on May 25, 2026 at 2:44 am

    In C, it’s safe to access any type as unsigned char [sizeof T]; this is called the representation. The question is whether copying this representation between diverse systems will preserve the value. Here are the relevant facts/issues:

    • All positive values of char (and keep in mind, all characters in the basic execution character set must be positive) have the same representation as an unsigned char with the same value. (The same applies to other signed/unsigned integer types too.)
    • On a twos-complement system, signed and unsigned char types are completely compatible (modulo the difference in how the values are interpreted) and it’s perfectly safe to access them as either type. Moreover, the C standard makes it difficult if not impossible to produce a valid implementation where plain char is signed and not twos-complement, and I think it’s safe to say no such implementation exists or will ever exist.
    • Even if the values as char (these are integers!) are preserved when transporting the file to another system, that doesn’t necessarily imply that the character identities will be preserved, since the target system might use a different character encoding (EBCDIC puke..).

    This is a lot of mumbo-jumbo, but the result you should take away is that unless your goal is pedantry and language-lawyering, there’s nothing to worry about. Just use fwrite and fread directly on strings and don’t worry about whether they were unsigned char[] or char[] strings.

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

Sidebar

Related Questions

Need to write (using fwrite()) some settings into php file in format: $var['key']['key']['key'] =
I inherited a site and need some help. There is a fwrite() function in
Need to insert selected text on the page into textarea. There must be some
#include<stdio.h> int main(int argc, char **argv){ FILE *fp = NULL; fp = fopen(D://test.txt,wb); if(fp
I need to download a text file using php code. The file is having
I have a very large binary file and I need to create separate files
I'd like to make copy of my binary file, but I need to make
I'm happily using proc_open to pipe data into another PHP process. something like this
I have an array being written to the file, but then I need a
For my research I need to deal with huge text file (10gi) of biological

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.