writing unsigned chars...

This is a discussion on writing unsigned chars... within the C++ Programming forums, part of the General Programming Boards category; i have a file im supposed to xor decrypt but for a different part i must read and write the ...

  1. #1
    Registered User
    Join Date
    Aug 2007
    Posts
    8

    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 myfile.read 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 08:58 AM.

  2. #2
    Registered User manofsteel972's Avatar
    Join Date
    Mar 2004
    Posts
    317
    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 http://xkcd.com/235/

  3. #3
    Registered User
    Join Date
    Aug 2007
    Posts
    8
    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
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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.

    --
    Mats

  5. #5
    Registered User
    Join Date
    Aug 2007
    Posts
    8
    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, 04:02 PM
  2. unable to recieve UDP packet
    By caroundw5h in forum Networking/Device Communication
    Replies: 15
    Last Post: 09-19-2007, 12:11 PM
  3. Heap corruption using zlib inflate
    By The Wazaa in forum C++ Programming
    Replies: 0
    Last Post: 03-29-2007, 01: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, 03: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

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