Operating System - HP-UX
1829404 Members
1842 Online
109991 Solutions
New Discussion

Re: EBCDIC to ASCII 'C' functions?

 
SOLVED
Go to solution
Greg White
Frequent Advisor

EBCDIC to ASCII 'C' functions?

Hi Experts,

Does anyone have a EBCDIC to ASCII conversion routine? My original versions were written in Pascal but I'd prefer not to recode them in C. The data files I have are a mixture of text and binary data. Please don't suggest that I use dd. I've already given up on that.

Thanks for any help or hints, Greg
I know how to do it in pascal.
3 REPLIES 3
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: EBCDIC to ASCII 'C' functions?

Hi Greg:

I just happen to have a routine like that in my pocket. This is actually two functions: ascii_2_ebcdic and ebcdic_2_ascii. Each of these take one unsigned char char as the argument as return the converted equivalent.

That should fix you.


Attached is ebcdic.c.

Regards, Clay

If it ain't broke, I can fix that.
Greg White
Frequent Advisor

Re: EBCDIC to ASCII 'C' functions?

Thank you, Cla.y.

I have a question about these functions. You have two sets of conversion tables. What's that for?

Thanks, Greg
I know how to do it in pascal.
A. Clay Stephenson
Acclaimed Contributor

Re: EBCDIC to ASCII 'C' functions?

If you man dd, you will see a conv=ebcdic and conv=ibm. These are slightly different character mapping. Because the vast majority of conversions I've had to do were from IBM's, I use the _IBM define. If you comment out the #define _IBM, you will get the conv=ebcdic table.

Many years ago, I actually created an ASCII file from ' ' to '~' and then converted to EBCDIC by running the file through dd. I then took that output and fed it to od and sed to generate the conversion tables that you see. I did one for conv=ibm and another for conv=ebcdic.

If it ain't broke, I can fix that.