How to write in DOS encoding using class FILE ?
How to write in DOS encoding using class FILE ?
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.
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);
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.
CharToOem();
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?