Thread: writing unsigned chars...

  1. #1
    Registered User
    Join Date
    Aug 2007

    writing unsigned chars...

    i have a file im supposed to xor decrypt but for a different part i must read and write the files using unsigned char* unfortunately the and myfile.write reject my unsigned char* buffer array...
    anyone know how to read and write files using unsigned chars, cause i couldnt find a thing...
    Last edited by comwizz2; 08-03-2007 at 07:58 AM.

  2. #2
    Registered User manofsteel972's Avatar
    Join Date
    Mar 2004
    My suggestion would be to look up type casting.
    "Knowledge is proud that she knows so much; Wisdom is humble that she knows no more."
    -- Cowper

    Operating Systems=Slackware Linux 9.1,Windows 98/Xp
    Compilers=gcc 3.2.3, Visual C++ 6.0, DevC++(Mingw)

    You may teach a person from now until doom's day, but that person will only know what he learns himself.

    Now I know what doesn't work.

    A problem is understood by solving it, not by pondering it.

    For a bit of humor check out xkcd web comic

  3. #3
    Registered User
    Join Date
    Aug 2007
    if i type cast the functions, it doesnt read or write them as unsigned char* witch changes some of the values becase they are over the limit of char

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    No, I doubt that very much - a signed char or a unsigned char looks the same in a file (or in computer memory) - it's only that a signed value uses the most significant bit as a sign, so if you have the value (unsigned)128, it is -128 signed, likewise unsigned 255 is -1. But they have exact same content either way.

    I very much doubt that read / write are doing any "interpretation" of the data, so you should be able to just cast the data-type that you read/write so that it matches the read/write function.


  5. #5
    Registered User
    Join Date
    Aug 2007
    thanks i found out another part of my code was causing it someone said check against null but i needed to still xor even if it was null

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Float To 3 unsigned chars
    By appleGuy in forum C++ Programming
    Replies: 8
    Last Post: 07-04-2009, 03:02 PM
  2. unable to recieve UDP packet
    By caroundw5h in forum Networking/Device Communication
    Replies: 15
    Last Post: 09-19-2007, 11:11 AM
  3. Heap corruption using zlib inflate
    By The Wazaa in forum C++ Programming
    Replies: 0
    Last Post: 03-29-2007, 12:43 PM
  4. Obtaining source & destination IP,details of ICMP Header & each of field of it ???
    By cromologic in forum Networking/Device Communication
    Replies: 1
    Last Post: 04-29-2006, 02:49 PM
  5. Writing structure in a unsigned char array
    By nasir_sidd in forum C++ Programming
    Replies: 1
    Last Post: 12-10-2002, 04:09 AM