Need help with C program

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • terry

    Need help with C program

    I am a programmer (cobol, peoplesoft, sqr, etc.) so I am familiar
    with programming logic, etc. but not very familiar with C. I need a C
    program in a study I'm doing. The program is fairly simple, but not
    familiar with C code it would take me some time to get it to work. A
    good C programmer can probably give me the code in a few minutes.

    Here's the program specs:

    I'm doing a study on the italicized words in the King James Bible. The
    italicized words are words not in the Greek and Hebrew text but were
    added by the translators for sentence structure, etc.

    I have a text file of the Old Testament and the New Testament. The
    italicized words are surrounded by brackets []. If a verse contains
    any italicized words I want to write that verse to a new flat-file
    that I will use in Word to look at, get counts, and do some grammar
    statistics, etc.

    Here's a sample of the input flat-file with a few verses from Genesis.
    Notice verses 2, 4, and 7 contain italicized words or brackets.

    1 In the beginning God created the heaven and the earth.
    2 And the earth was without form, and void; and darkness [was] upon
    the face of the deep. And the Spirit of God moved upon the face of the
    waters.
    3 And God said, Let there be light: and there was light.
    4 And God saw the light, that [it was] good: and God divided the light
    from the darkness.
    5 And God called the light Day, and the darkness he called Night. And
    the evening and the morning were the first day.
    6 And God said, Let there be a firmament in the midst of the waters,
    and let it divide the waters from the waters.
    7 And God made the firmament, and divided the waters which [were]
    under the firmament from the waters which [were] above the firmament:
    and it was so.
    8 And God called the firmament Heaven. And the evening and the morning
    were the second day.

    So my output file would look like

    2 And the earth was without form, and void; and darkness [was] upon
    the face of the deep. And the Spirit of God moved upon the face of the
    waters.
    4 And God saw the light, that [it was] good: and God divided the light
    from the darkness.
    7 And God made the firmament, and divided the waters which [were]
    under the firmament from the waters which [were] above the firmament:
    and it was so.

    The logic I came up with would be something like:

    Read a character from the flat-file:
    Check for a number
    If number (indicates a new verse)
    If a "[" is found (found_flag) from previous verse
    write the WORK AREA stored verse to the output file.
    Possibly need to write an eol character
    Clear out the work area
    Clear out the found [ flag

    If a [ is NOT found (found-flag) then
    clear the stored verse

    Move each character to a WORK AREA
    Check each character for a "["
    If found set the found_flag = y

    Got get another character

    Another variation I would like to do is create an output file of JUST
    the italicized words or bracketed words.

    A couple of questions or issues:

    How large a file can C read?
    The Old Testament file is 3,282,275 characters (size is 3,342,336
    bytes) If needed I could cut up the files.

    Is there a better way?

    I will probably use Borland C+ as the compiler.

    If possible, please email any solutions to twatkins@charte r.net

    Thank you very much for your time and expertise.
  • Gianni Mariani

    #2
    Re: Need help with C program [OT]


    This question is off topic for comp.lang.c++ - comp.object or
    comp.programmin g would be better.

    terry wrote:
    ..... big snip[color=blue]
    >
    > Is there a better way?[/color]

    Yes. If this is all you want to do, a database (like PostgreSQL) would
    manage this in a one liner.

    Or even better, "grep '\\[' bible.txt" does the job.
    [color=blue]
    >
    > I will probably use Borland C+ as the compiler.
    >
    > If possible, please email any solutions to twatkins@charte r.net
    >
    > Thank you very much for your time and expertise.[/color]

    Most modern computers can read 5 or six bibles into "memory" without
    breaking a sweat.

    Before I could reccomend a class design, I'd need to know much more
    about the kinds of things that you want to do.

    Here is a stab in the dark.

    class Verse
    {
    public:

    std::string m_verse;

    bool HasItalics();
    };

    class Bible
    {
    public:

    std::list<Verse > m_verses;
    };


    int main()
    {

    Bible b;

    ReadBible( b );

    std::list<Verse > italicslist;

    std::list<Verse >::iterator i_end = b.m_verses.end( );

    for (
    std::list<Verse >::iterator i = b.m_verses.begi n();
    i != i_end;
    i ++
    ) {
    if ( i->HasItalics() ) {
    italicslist.ins ert( *i );
    }
    }

    WriteVerses( italicslist );

    }

    It probably makes a few copies of objects it need not do but before we
    go optimize anything you need to have a few more requirements nailed down.

    .... not very useful yet.

    Comment

    Working...