Pregunta

If I have a character array that is in EBCDIC format and I want to save that array to a file. I'm thinking of using fputs to output the character array without first converting it to another format.

Question) Is the use of fputs legal for writing EBCDIC? If not, should I convert the string to ASCII before outputting?

I've search online, but couldn't find anything to say fputs should not be used for outputting EBCDIC data.

¿Fue útil?

Solución

If your character array that is in EBCDIC format is a c-style string in that in ends with a \0 byte, then there is no problem.

fputs(), in binary mode, is format agnostic other than it does not write a \0.

Assuming your program is written using the ASCII char set, it is important that your output file is opened in binary mode (e. g. "wb"), else the \n of C will not match the same in EBCDIC and some translations are possible.

On the other hand, are you going to do something with this file other than write and maybe read back?


Should your "character array that is in EBCDIC format" not end in \0 or have embedded \0 bytes, suggest you simple use fwrite(). Again be sure to use in binary mode, unless your entire system is EBCDIC.

Otros consejos

Well, fputs takes a C string, and that uses the ASCII encoding . So, that won't work. I think you'll need to write the file using a lower level function. Perhaps use fwrite to write the file directly without using strings. Here's the man page on fwrite.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top