hex writing stuff

This is a discussion on hex writing stuff within the C++ Programming forums, part of the General Programming Boards category; hello, I got this offset in a file "0X000626C5". the original hex number is 28 and i want to change ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    56

    Question hex writing stuff

    hello,
    I got this offset in a file "0X000626C5".
    the original hex number is 28 and i want to change it to 27, my only problem is how do i write it in c++
    i tryd google and search function on this forum,
    if any1 can help me thx, gamer.

    edit:
    is this possible in dev-cpp or should i use vc 2003'?
    Last edited by gamer; 01-04-2005 at 04:05 AM.
    if x == y , y == x

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    Roughly speaking, you
    - open the file for update
    - seek to offset 0x626c5
    - write a single char

    Something like this (you can look up the details from here)
    f.open("file");
    f.seek(0x626c5);
    f.putc(27);

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    56
    so basicly with seek you can just find the location of the offset?

    quickedit:
    so i can do the same with f.seek to get what is there currently
    if x == y , y == x

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    > so i can do the same with f.seek to get what is there currently
    Yes, if you consider a file as an array of characters, then seek is the subscripting operator, and getc() and putc() are the access functions.

    array[10] = 2;

    file.seek(10);file.putc(2);

    One trap to watch for is that with a file you should use flush() following a write operation, especially if you intend to follow on with some read operations.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. References vs Pointer vs copying and storing stuff in classes
    By Monkeymagic in forum C++ Programming
    Replies: 20
    Last Post: 09-01-2006, 09:40 AM
  2. Writing 64 bit value in hex to a string
    By rahulgbe in forum C Programming
    Replies: 2
    Last Post: 03-18-2006, 12:15 PM
  3. Folding@Home Cboard team?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 398
    Last Post: 10-11-2005, 08:44 AM
  4. Printing Hex as Binary
    By Mystic_Skies in forum C Programming
    Replies: 6
    Last Post: 11-22-2004, 03:18 PM
  5. converting hex to dec
    By jibbles in forum C Programming
    Replies: 20
    Last Post: 08-07-2004, 11:40 PM

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