473,659 Members | 2,934 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Write a string in EBCDIC

I need to write a string to a file in EBCDIC.

Do I need to do it character by character using a translation table,
or is there a function to translate the whole string?

(I am aware that I can convert a whole file using Unix utilities, but
this file will have only a few header records in EBCDIC)
Nov 14 '05 #1
12 4634
jo********@mada safish.com (John Leslie) wrote:
# I need to write a string to a file in EBCDIC.
#
# Do I need to do it character by character using a translation table,
# or is there a function to translate the whole string?
#
# (I am aware that I can convert a whole file using Unix utilities, but
# this file will have only a few header records in EBCDIC)

http://www.room42.com/store/computer...ranslate.shtml

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Don't say anything. Especially you.
Nov 14 '05 #2
John Leslie wrote:

I need to write a string to a file in EBCDIC.

Do I need to do it character by character using a translation
table, or is there a function to translate the whole string?


If the system native char set is EBCDIC, just write the string.
The whole problem is system specific, not language specific, and
thus is off-topic in c.l.c. It requires knowing both the source
and destination char sets and their coding. I would create a
translation function, and customize it for each specific system.

Try a group that deals with your specific system.

--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
Nov 14 '05 #3
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

SM Ryan wrote:
| jo********@mada safish.com (John Leslie) wrote:
| # I need to write a string to a file in EBCDIC.
| #
| # Do I need to do it character by character using a translation table,
| # or is there a function to translate the whole string?
| #
| # (I am aware that I can convert a whole file using Unix utilities, but
| # this file will have only a few header records in EBCDIC)
|
| http://www.room42.com/store/computer...ranslate.shtml

I'd be cautious in using that example. For one thing, it doesn't indicate
/which/ EBCDIC it is translating ASCII to, and for another, it performs at
least 256 improper ASCII-to-EBCDIC conversions, if not more.

For what it's worth, there are about 30 different EBCDIC variants, each with
differences in the order and codepoint of common characters, and the
assignment of codepoints to disparate characters. You might want to take a
look at the various characterset mappings at http://anubis.dkuug.dk/i18n/charmaps/


- --
Lew Pitcher

Master Codewright & JOAT-in-training | GPG public key available on request
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFAy8VLagV FX4UWr64RAhUTAJ wKsjG10yqHt3ekE xcB3Mh8e0TdWgCg sxnz
c4MlgfDNzFr6oh/JVg3ju9I=
=+wfr
-----END PGP SIGNATURE-----
Nov 14 '05 #4
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Lew Pitcher wrote:
| SM Ryan wrote:
| | jo********@mada safish.com (John Leslie) wrote:
| | # I need to write a string to a file in EBCDIC.
| | #
| | # Do I need to do it character by character using a translation table,
| | # or is there a function to translate the whole string?
| | #
| | # (I am aware that I can convert a whole file using Unix utilities, but
| | # this file will have only a few header records in EBCDIC)
| |
| | http://www.room42.com/store/computer...ranslate.shtml
|
| I'd be cautious in using that example. For one thing, it doesn't indicate
| /which/ EBCDIC it is translating ASCII to, and for another, it performs at
| least 256 improper ASCII-to-EBCDIC conversions, if not more.

Correction - I meant "at least 128 improper ASCII-to-EBCDIC conversions"
- --
Lew Pitcher

Master Codewright & JOAT-in-training | GPG public key available on request
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFAy8XnagV FX4UWr64RAvlCAJ 4tuCL5Rb8GWKYZ6 SmZgh1MQ2NsoACf Yhcz
hySLhMx4qKqqi+J jKfSeFnE=
=8/jR
-----END PGP SIGNATURE-----
Nov 14 '05 #5
CBFalconer <cb********@yah oo.com> wrote:
John Leslie wrote:

I need to write a string to a file in EBCDIC.

Do I need to do it character by character using a translation
table, or is there a function to translate the whole string?


If the system native char set is EBCDIC, just write the string.
The whole problem is system specific, not language specific, and
thus is off-topic in c.l.c. It requires knowing both the source
and destination char sets and their coding. I would create a
translation function, and customize it for each specific system.

Try a group that deals with your specific system.


Is it really off-topic? I'm not so sure. The problem can be solved
in a 100% portable way that is not system-specific at all:

void setup_xlate_tab le(void)
{
...

xlate['a'] = /* EBCDIC value for 'a' */;
xlate['b'] = /* EBCDIC value for 'b' */;
xlate['c'] = /* EBCDIC value for 'c' */;

...
}

Write a translate function and voila, you have a portable
native-charset-to-EBCDIC-charset conversion solution.
Nov 14 '05 #6
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

no****@nowhere. com wrote:
CBFalconer <cb********@yah oo.com> wrote:
John Leslie wrote:
I need to write a string to a file in EBCDIC.

Do I need to do it character by character using a translation
table, or is there a function to translate the whole string?


If the system native char set is EBCDIC, just write the string.
The whole problem is system specific, not language specific, and
thus is off-topic in c.l.c. It requires knowing both the source
and destination char sets and their coding. I would create a
translation function, and customize it for each specific system.

Try a group that deals with your specific system.

Is it really off-topic? I'm not so sure. The problem can be solved
in a 100% portable way that is not system-specific at all:

void setup_xlate_tab le(void)
{
...

xlate['a'] = /* EBCDIC value for 'a' */;
xlate['b'] = /* EBCDIC value for 'b' */;
xlate['c'] = /* EBCDIC value for 'c' */;

...
}

Write a translate function and voila, you have a portable
native-charset-to-EBCDIC-charset conversion solution.


1) /which/ EBCDIC?

2) How do you handle characters that exist in ASCII, but not in the target
EBCDIC? For instance, how do you translate 0x5d (ASCII ']') to EBCDIC-US?

3) How do you handle char values that are not ASCII to begin with? For
instance, how do you translate 0x9A (not an ASCII character) to EBCDIC-US?
- --
Lew Pitcher

Master Codewright & JOAT-in-training | GPG public key available on request
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFAy9ZPagV FX4UWr64RAlp+AJ 459ha4S4Gyi46PK 9ZOeRsDsWdNgwCf UHN4
3joRaeW+GWPREx/MQDjVBkM=
=ImUU
-----END PGP SIGNATURE-----
Nov 14 '05 #7
"Lew Pitcher" <lp******@sympa tico.ca> wrote:
no****@nowhere. com wrote:
Is it really off-topic? I'm not so sure. The problem can be solved
in a 100% portable way that is not system-specific at all:

void setup_xlate_tab le(void)
{
...

xlate['a'] = /* EBCDIC value for 'a' */;
xlate['b'] = /* EBCDIC value for 'b' */;
xlate['c'] = /* EBCDIC value for 'c' */;

...
}

Write a translate function and voila, you have a portable
native-charset-to-EBCDIC-charset conversion solution.
1) /which/ EBCDIC?


Write a separate setup_xlate_tab le function for each EBCDIC you are
interested in.
2) How do you handle characters that exist in ASCII, but not
in the target EBCDIC? For instance, how do you translate
0x5d (ASCII ']') to EBCDIC-US?

3) How do you handle char values that are not ASCII to begin
with? For instance, how do you translate 0x9A (not an ASCII
character) to EBCDIC-US?


Simple answer: Replace it with a question mark, issue a warning.

Complex answer: Do whatever's appropriate for the particular type of file
you're translating.

--
Simon.
Nov 14 '05 #8
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ralmin wrote:
"Lew Pitcher" <lp******@sympa tico.ca> wrote:
no****@nowher e.com wrote:
Is it really off-topic? I'm not so sure. The problem can be solved
in a 100% portable way that is not system-specific at all:

void setup_xlate_tab le(void)
{
...

xlate['a'] = /* EBCDIC value for 'a' */;
xlate['b'] = /* EBCDIC value for 'b' */;
xlate['c'] = /* EBCDIC value for 'c' */;

...
}

Write a translate function and voila, you have a portable
native-charset-to-EBCDIC-charset conversion solution.
1) /which/ EBCDIC?

Write a separate setup_xlate_tab le function for each EBCDIC you are
interested in.


OK, so about thirty setup_xlate_tab le functions, and the /caller/ has to know
which EBCDIC to select. That means that the caller needs to incorporate the
infrastructure to determine which target EBCDIC is the one to use, and his
logic needs to encorporate some sort of user input query (cmdline options or
envvar checking or user-interactive options). From /my/ experience (and I've
had a lot of experience), it's not easy.
2) How do you handle characters that exist in ASCII, but not
in the target EBCDIC? For instance, how do you translate
0x5d (ASCII ']') to EBCDIC-US?

3) How do you handle char values that are not ASCII to begin
with? For instance, how do you translate 0x9A (not an ASCII
character) to EBCDIC-US?

Simple answer: Replace it with a question mark, issue a warning.


Bzzt. Wrong answer. Or, at least wrong replacement value. Tell me what the
correct replacement value should be. Also, issue a warning how, and to whom?

Speaking from experience, substitution is the 'correct' way to go, but also
the wrong way to go. Assume that the data the OP wants to translate looks like

#include <stdio.h>
int main(void)
{
char text[] = "2^3 = 8\n";
printf("%s",tex t);
return 0;
}

Will single character substitution result in an EBCDIC file that preserves the
meaning of the translated ASCII data? I can answer simply: no, it will not.
Square brackets do not exist in some EBCDIC variants, and exist with different
codepoints (varying in value from EBCDIC variant to variant) in others. The
caret symbol doesn't exist in most EBCDIC variants, and is typically
translated to the PL/1 'logical not' sign ( which sort of looks like: '-|' ).
Substituting '?' (or even the proper SUB character) for the untranslatable
characters would invalidate the meaning of the data being transferred. In this
case, with your suggested substitution, the data becomes

#include <stdio.h>
int main(void)
{
char text?? = "2?3 = 8\n";
printf("%s",tex t);
return 0;
}

Which results in a textual file that is /not/ equivalent to the original text
file.

Complex answer: Do whatever's appropriate for the particular type of file
you're translating.


Closer, but that's the whole point of this exercise. The OP wants to
"translate ASCII to EBCDIC"; that's the "particular type of file" he's
translating. What is appropriate for that?
- --
Lew Pitcher

Master Codewright & JOAT-in-training | GPG public key available on request
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFAzJLxagV FX4UWr64RAmsbAJ 9d75Xv3Nsuepz8/FSgp0ITt5K3ygCg xCuD
etMA7J9MHahzBZ5 RySpiajo=
=lBrZ
-----END PGP SIGNATURE-----
Nov 14 '05 #9
Lew Pitcher wrote:
Ralmin wrote:
.... snip ...
Which results in a textual file that is /not/ equivalent to the
original text file.
Complex answer: Do whatever's appropriate for the particular
type of file you're translating.


Closer, but that's the whole point of this exercise. The OP
wants to "translate ASCII to EBCDIC"; that's the "particular
type of file" he's translating. What is appropriate for that?


Seems to me that one rule that the tables should observe is
uniqueness. I.e. whether or not the translation makes sense, the
result should be translatable back into the original without
loss. In a way this is what happens when you pack a text file
into a zip file. The algorithm is lossless.

--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!

Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
49582
by: joel.brewster | last post by:
We have a VB6 application using ADO version 2.5 and I am receiving a " CLI0109E String data right truncation. SQLSTATE=22001" error when I execute the rs.UpdateBatch method. I have determined that the error is caused by an extended ascii character 164 (ñ). Has anyone else encountered this problem and found a solution. TIA Joel Brewster Mutual Of Omaha
6
925
by: R.A. | last post by:
Hi Is there some support for this file conversion in c#? Thanks
2
1338
by: Ranjan | last post by:
Hi folks! I am trying to convert EBCDIC file to ASCII file. the issues are 1) Can all EBCDIC file be converted to ASCII without loss of information.(There is one character cent sign which is not in ASCII, how to handle that?) 2)What about non printable characters in EBCDIC, do they all converted to ASCII format? Suggest some way. Thanks n Regards Ranjan
9
6750
by: jeff M via .NET 247 | last post by:
I'm still having problems reading EBCDIC files. Currently itlooks like the lower range (0 to 127) is working. I have triedthe following code pages 20284, 20924, 1140, 37, 500 and 20127.By working I get the correct answer by taking the decimal valueand using that as an index to an array that will map to thecorrect EBCDIC value in hex. By larger values, an example would be "AA" in EBCDIC hex wouldgive me the value of 63 in decimal (ASCII) when...
5
1749
by: Ross | last post by:
I have a quick question regarding printing string constants. When you printf() a string constant, how are the characters encoded that get sent to the standard output? Is it in the execution character set? Thanks in advance.
6
2606
by: Ven | last post by:
Hi, I am reading a kind of below mentioned raw data into my C++ program and writing it out but I want this to be converted into EBCDIC format, how can I accomplish this ? Right now I am using the following code ifstream Source("source_file"); ofstream Dest("dest_file");
0
3424
by: Srini | last post by:
Hello, Using unload JCL utility DSNUPROC I unloaded a table(which is in unicode) to a dataset. I want the unload to be in EBCDIC format. I used the unload option EBCDIC, but I am not able to get the output dataset in EBCDIC format. UNLOAD statement I used is:
4
6520
by: =?Utf-8?B?ai5hLiBoYXJyaW1hbg==?= | last post by:
Hi, I have read the "how to's" on MSDN including this one, http://msdn2.microsoft.com/en-us/library/36b93480.aspx, on reading/writing files in C#, but haven't found something that I can put together that is working. The file I have is in EBCDIC, rec length = 250 and delimited by CRLF's. What I want to do is open an EBCDIC file in Read/Write mode so I can read the record, alter the data in a fixed set of positions (position 2, zero
44
3842
by: Pilcrow | last post by:
Is there a way that a proram can detect whether it is operating in an ASCII or an EBCDIC environment?
0
8427
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8332
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8525
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8627
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7356
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6179
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.