redirection and binary files

This is a discussion on redirection and binary files within the C Programming forums, part of the General Programming Boards category; currently studying redirection in my C book and was wondering if its possible to use redirection to read a binary ...

  1. #1
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751

    redirection and binary files

    currently studying redirection in my C book and was wondering if its possible to use redirection to read a binary file. I tried to read an excel file for example and i just got a bunch of weird characters and spacees. Any ideas why?

  2. #2
    Registered User
    Join Date
    Dec 2003
    Posts
    53
    How exactly did you try to read the excel file? Do you know the file format they use to store data in the excel file? (I know I don't...)

    Also, in order to read binary files, you need to use fread.

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,646
    >> Any ideas why?
    Because it's binary.

    Binary files contain bytes which aren't necessarily printable.

    gg

  4. #4
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    Think about it...If i write to a file with a stucture declared as
    Code:
    struct info{
         int x;
         short y;
         char *width;
         double z;
         long long cat;
    };
    and you read it with something like a character array, what do you think you'll get. Meaningless garbage(basically) You need to read with that same type of struct to get what you want.

  5. #5
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    >>>to linuxdude.

    Which you never know cause it could be anything. I guess thats makes sense.

    in regards to how i read the file
    from the command line, in the same directory where the files are:

    read < vocab.txt

    where read is a .exe in C to read each character unitl EOF and vocab is a text document.

  6. #6
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    It is mentioned here that it may be possible to use a nonstandard function to reopen the stdin in binary mode.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  7. #7
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    Quote Originally Posted by Dave_Sinkula
    It is mentioned here that it may be possible to use a nonstandard function to reopen the stdin in binary mode.
    Thanks for the link.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linux file redirection buffering issue !!!!
    By AirSeb in forum Linux Programming
    Replies: 8
    Last Post: 03-14-2009, 05:32 PM

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