Thread: low level I/O

  1. #1
    Registered User
    Join Date
    Jan 2004
    Posts
    3

    low level I/O

    I'm using the write() function something like this:

    write(fildes, write_value, sizeof(n));

    ie. I want to write a single integer value to filedes file. The integer is successfully written, but there is always a garbage value like t^@^@ appended to the end and I cannot understand why... by my (admittedly not rock solid) logic, only the correct number of bytes for an int should be written...

    If someone could clue me in on the reason this happens, I should hopefully be able to fix it...

    thanks

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Are you expecting to be able to read the number in the text file? As you're using write() to output an int, the actual number will be written at a binary level, and won't be readable in a normal text viewer.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Jan 2004
    Posts
    3
    I must say, I'm really confused then, since I can read the proper number. There is some junk after it, however.

    It seems like the two requirements, (a) that open, close, read, write are used and (b) that the file is a text file, conflict? All very confusing.

    Sorry, it is my first time programming in C for an OS course and I feel like an idiot, but I'm just trying to do what I'm told

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    What are fildes, write_value, and n defined as?
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  5. #5
    Registered User
    Join Date
    Jan 2004
    Posts
    3
    n is an int passed to the function.

    Code:
    int *write_value;
    write_value = &n;
    fildes is the file descriptor of an open file.

  6. #6
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    sizeof(int)?

  7. #7
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Post enough code for us to compile that shows your problem.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Low level program to save a mjpeg stream
    By Rufe0 in forum Linux Programming
    Replies: 6
    Last Post: 09-22-2009, 05:53 AM
  2. C/C++, low or high level?
    By Sentral in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 01-23-2007, 11:43 PM
  3. Low Level Drive Access?
    By coldfusion244 in forum C++ Programming
    Replies: 1
    Last Post: 03-09-2005, 08:19 AM
  4. Overlapped I/O and Completion Port :: Winsock
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 10-30-2002, 05:14 PM
  5. Low level debuggers
    By Korn1699 in forum C++ Programming
    Replies: 8
    Last Post: 03-27-2002, 01:39 PM