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

This is a discussion on turning the contents of a file into a string using the preprocessor? within the C Programming forums, part of the General Programming Boards category; A project I am working on includes a text file containing some version information (just letters, numbers, and spaces, nothing ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    1

    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:

    Code:
    char * version = "#include "file"";
    Thanks.

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

    Code:
    #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
    Location
    TX
    Posts
    2,047
    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, 10: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

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