Thread: turning the contents of a file into a string using the preprocessor?

  1. #1
    Registered User
    Join Date
    Mar 2009

    turning the contents of a file into a string using the preprocessor?

    A project I am working on includes a text file containing some version information (just letters, numbers, and spaces, nothing that ordinarily would have to be escaped). Is it possible to use the C preprocessor to turn the contents of this file into a string? Something equivalent to the following, if it worked:

    char * version = "#include "file"";

  2. #2
    Registered User
    Join Date
    Apr 2006
    Something like this might work. If not I can't think of a way.

    #define STR(ARG) #ARG
    char * version = STR(
    #include "file"
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  3. #3
    Registered User
    Join Date
    Oct 2008
    Another way could be to seek to the end of the file; get its length with ftell(); and then store all of it using a single fread().

    Edit: never mind as you wanted something using the preprocessor.
    Last edited by itCbitC; 03-08-2009 at 09:19 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 04:25 AM