Thread: Class FILE to write in DOS encoding.

  1. #1
    Registered User
    Join Date
    Dec 2013
    Posts
    4

    Class FILE to write in DOS encoding.

    How to write in DOS encoding using class FILE ?

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,908
    C doesn't have classes. FILE is an object (not in the object-oriented sense), but is "opaque", i.e. you can't see what it's members are, and it does not have any functions in it, though there are standard functions that operate on FILE objects. Neither the FILE object, nor any of the standard C functions, have any concept of file encoding, let alone DOS encoding.

    Can I assume by DOS encoding, you are referring to the fact that DOS and Windows use \r\n to mark the end of a line, whereas, e.g., Linux uses \n?

    If you're programming on DOS (eek! time to update) or Windows, then your implementation (compiler and libraries) should use DOS encoding by default, so long as you open the file in text mode (see the fopen documentation). If not, you will have to do the work yourself to translate each '\n' to a "\r\n" sequence (or vice-versa). Exactly what you want to read from or write to this file will affect when and how you translate the sequence.

  3. #3
    Registered User
    Join Date
    Dec 2013
    Posts
    4
    I'm using

    CString text;
    CString file_name;
    text = "My text must be in txt file in MS-DOS encoding.";
    file_name = "MyFile.txt";
    FILE *fp;
    fp = fopen(file_name, "w+");
    fprintf(fp, text + "\n");
    fclose(fp);

  4. #4
    Registered User
    Join Date
    Apr 2013
    Posts
    1,658
    If you open the file in binary mode, "wb+", then use fprintf(... "\r\n"); it should create a DOS text file even on windows or linux type systems. If you're running a version of windows, then what you already have should be ok.

  5. #5
    Registered User
    Join Date
    Dec 2013
    Posts
    4
    CharToOem();

  6. #6
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,908
    You're very vague in your posts, making our jobs very difficult. Do you mean that function does what you want? Are you asking us if that function does what you want? Are you telling us you're using it, whether or not it really does what you want? Or are you merely informing us that there is such a function?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Encoding a data structure based on TLV encoding
    By Sajas K K in forum C++ Programming
    Replies: 2
    Last Post: 02-15-2013, 10:39 PM
  2. Decoding and Encoding from file?
    By rvbplayer123 in forum C++ Programming
    Replies: 2
    Last Post: 11-17-2012, 05:30 PM
  3. How to convert string in url encoding to html encoding?
    By Jerel2k11 in forum C Programming
    Replies: 6
    Last Post: 11-06-2011, 09:05 AM
  4. To Encoding Format of File
    By samirpadhy in forum C++ Programming
    Replies: 2
    Last Post: 06-09-2009, 11:48 PM
  5. How to check file encoding ?
    By desmond5 in forum C Programming
    Replies: 13
    Last Post: 03-11-2008, 02:34 PM

Tags for this Thread