Converting a PRN file to a CSV using C++

S

spacepie

Does anyone have sample coding to do this. I have a legacy app which
generates great data but it's in PRN format. I need to convert this to CSV
format for importing. I don't know C++ well enouch yet to code from
scratch. I could learn quickly from an example that reads,formats then
outputs. If anyone has an example code I would like to see it.

Thanks,
Spacepie
 
H

Howard

spacepie said:
Does anyone have sample coding to do this. I have a legacy app which
generates great data but it's in PRN format. I need to convert this to CSV
format for importing. I don't know C++ well enouch yet to code from
scratch. I could learn quickly from an example that reads,formats then
outputs. If anyone has an example code I would like to see it.

Neither PRN nor CSV formats has anything to do with the c++ language, which
is what is discussed here. You'll need to find a group which discusses
things more relevant to those formats (whatever they are), whether that's
something related to the company who specified those formats, or the OS
they're used on, or whatever. Your best bet is probably to go to
groups.google.com, and search for those terms, perhaps along with words like
"convert" or "translate".

-Howard
 
S

spacepie

Howard,
C++ can, open a text file, read the data into an array then parse segments
of that array to an output file with coma delimiters. Why are telling me to
go somewhere else? I want to learn C++ thus I've taken the time to join
this forum. I thought I could get help from friend people.
 
S

Sherm Pendley

spacepie said:
C++ can, open a text file, read the data into an array then parse segments
of that array to an output file with coma delimiters.

Yes it can. Which one of those steps are you having trouble with? What have
you tried so far? What results did you expect, and what results did you get?
Why are telling me to go somewhere else?

Who told you that? In what message? Please - quote enough of the message you
are replying to for your own message to make sense.

sherm--
 
H

Howard

spacepie said:
Howard,
C++ can, open a text file, read the data into an array then parse segments
of that array to an output file with coma delimiters. Why are telling me
to
go somewhere else? I want to learn C++ thus I've taken the time to join
this forum. I thought I could get help from friend people.

You asked how to translate PRN to CSV, and that requires knowledge of the
formats of those files, which is not related to anything in the C++
language. If you need to know how to read and write files, you could try
searching on groups.google.com for examples, or read in a book about
streams. But we'll be glad to help with a specific problem with the
language. (For isntance, if you find an example, but it doesn't compile and
you don't know why, etc.)

-Howard
 
J

Jim Langston

spacepie said:
Does anyone have sample coding to do this. I have a legacy app which
generates great data but it's in PRN format. I need to convert this to CSV
format for importing. I don't know C++ well enouch yet to code from
scratch. I could learn quickly from an example that reads,formats then
outputs. If anyone has an example code I would like to see it.

Thanks,
Spacepie

I believe PRN is pure ASCII text, and CSV is Comma Separated Variable, is
that correct?

Or example, PRN might be:
123 456 789 012 abc

and you want to convert it to
123,456,789,012,abc

is that correct?

So, basically you want to read a line, then read each string in that line.
Print out each string and a "," until you come to the end of the line. Then
print a newline and read the next line.

But, you have to tell us, what is the format of the PRN file, is it how I
stated above? What is the format of the CSV file, is it as I stated above?
 
S

spacepie

Hi Jim,
Thank you for your time. Your understanding of my description and the file
structures are accurate. The precise PRN record layout is 104 columns in
length. The field breakdown is space delimited and looks like this:
F1 = 1-5
F2 = 7-12
F3 = 14-42
F4 = 44-46
F5 = 48-55
F6 = 57-74
F7 = 76-79
F8 = 81-95
F9 = 97-98
F10 =100-104
In this case would I place each record in an array or a variable? What is
the "Substr" command to define the fields.
Thanks for the help
 
K

Karl Heinz Buchegger

spacepie said:
Hi Jim,
Thank you for your time. Your understanding of my description and the file
structures are accurate. The precise PRN record layout is 104 columns in
length. The field breakdown is space delimited and looks like this:
F1 = 1-5
F2 = 7-12
F3 = 14-42
F4 = 44-46
F5 = 48-55
F6 = 57-74
F7 = 76-79
F8 = 81-95
F9 = 97-98
F10 =100-104
In this case would I place each record in an array or a variable? What is
the "Substr" command to define the fields.
Thanks for the help

eg. (warning: untested, not compiled code)

ifstream in;
ofstream out;
// mumbo, jumbo to deal with opening the files

std::string line;
while( getline( file, in ) ) {
out << line.substr( 0, 5 ) << ',' // 5 - 1 + 1
<< line.substr( 7, 6 ) << ',' // 12 - 7 + 1
<< line.substr( 14, 29 ) << ',' // 42 - 14 + 1
<< ....
<< '\n';
}

getline() reads a complete input line into a string.
substr() extracts sub-strings.

substr() expects: position to start (as usual, start with 0)
length of sequence
 
S

spacepie

Karl,
Belated thanks for your input. It did help and upgrading the compiler
version to Borland's C++ Builder 5 removed many errors I thought were
mine. With a stable enviroment I can now learn more about C++ code.
Accolades to those of you who have been compass points.
Rgds,
spacepie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top