Converting a PRN file to a CSV using C++

Discussion in 'C++' started by spacepie, Sep 16, 2005.

  1. spacepie

    spacepie Guest

    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
     
    spacepie, Sep 16, 2005
    #1
    1. Advertising

  2. spacepie

    Howard Guest

    "spacepie" <> wrote in message
    news:...
    > 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
     
    Howard, Sep 16, 2005
    #2
    1. Advertising

  3. spacepie

    spacepie Guest

    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.
     
    spacepie, Sep 16, 2005
    #3
  4. "spacepie" <> writes:

    > 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--

    --
    Cocoa programming in Perl: http://camelbones.sourceforge.net
    Hire me! My resume: http://www.dot-app.org
     
    Sherm Pendley, Sep 16, 2005
    #4
  5. spacepie

    Howard Guest

    "spacepie" <> wrote in message
    news:...
    > 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
     
    Howard, Sep 16, 2005
    #5
  6. spacepie

    Jim Langston Guest

    "spacepie" <> wrote in message
    news:...
    > 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?
     
    Jim Langston, Sep 17, 2005
    #6
  7. spacepie

    spacepie Guest

    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
     
    spacepie, Sep 19, 2005
    #7
  8. spacepie wrote:
    >
    > 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

    --
    Karl Heinz Buchegger
     
    Karl Heinz Buchegger, Sep 19, 2005
    #8
  9. spacepie

    spacepie Guest

    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
     
    spacepie, Sep 21, 2005
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SpamProof
    Replies:
    0
    Views:
    3,588
    SpamProof
    Oct 21, 2003
  2. Tintin92
    Replies:
    1
    Views:
    1,716
    Andrew Thompson
    Feb 14, 2007
  3. Johanna Pfalz

    Converting a .dbf file to a CSV file

    Johanna Pfalz, Nov 2, 2006, in forum: Python
    Replies:
    1
    Views:
    384
    John Machin
    Nov 2, 2006
  4. jliu66
    Replies:
    0
    Views:
    516
    jliu66
    Oct 19, 2007
  5. Li Chen
    Replies:
    18
    Views:
    668
    Azmi Farih
    Mar 23, 2010
Loading...

Share This Page