Using a char-array in stead of an external data file

This is a discussion on Using a char-array in stead of an external data file within the C++ Programming forums, part of the General Programming Boards category; I have a char-array with the binary data of a file, and a function that takes a FILE pointer. Can ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    2

    Using a char-array in stead of an external data file

    I have a char-array with the binary data of a file, and a function that takes a FILE pointer.
    Can I in some way give the function the data in my char-array in stead of writing it to an external file and then open this file using fopen or similar?

    Thanks in advance.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    No, not really. If you can change the function then you would be able to pass an istream to the function. Then instead of a char array you could put the data in a stringstream and pass that. If you can't change the function then you're pretty much stuck with using a temporary file:
    Code:
    void callee(FILE *in);
    
    void
    caller(
      char   *buffer,
      size_t  size
      )
    {
      FILE *temp = tmpfile();
    
      if (!temp) {
        // Error
      }
      fwrite(buffer, 1, size, temp);
      rewind(temp);
      callee(temp);
      fclose(temp);
    }
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  3. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM
  4. I'm having a problem with data files.
    By OmniMirror in forum C Programming
    Replies: 4
    Last Post: 05-14-2003, 09:40 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM

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