file processing in c

Discussion in 'C Programming' started by wolky, Mar 27, 2007.

  1. wolky

    wolky Guest

    hi all my friends...
    ý have a problem with file processing in c... ý have some questions
    about it...
    ý have two txt files... in first one there is a text, in second one
    there are words that ý want to remove these words from first one...
    how can ý remove those words from first one?

    thx all for ur help
    wolky, Mar 27, 2007
    #1
    1. Advertising

  2. wolky

    Nelu Guest

    On Mar 26, 8:33 pm, "wolky" <> wrote:
    > hi all my friends...
    > ý have a problem with file processing in c... ý have some questions
    > about it...
    > ý have two txt files... in first one there is a text, in second one
    > there are words that ý want to remove these words from first one...
    > how can ý remove those words from first one?
    >
    > thx all for ur help


    You'll have to attempt to solve the problem yourself then come back
    and show us your attempt if you want to get help.

    Right now I can tell you to look up:
    <stdio.h>
    fopen
    fgets
    fclose

    You may also want to check out:
    <string.h>
    strncmp
    *or*
    strstr

    And for something extra:
    strstr
    <errno.h>
    errno

    --
    Ioan - Ciprian Tandau
    tandau _at_ freeshell _dot_ org (hope it's not too late)
    (... and that it still works...)
    Nelu, Mar 27, 2007
    #2
    1. Advertising

  3. wolky

    Nelu Guest

    On Mar 26, 8:58 pm, "Nelu" <> wrote:
    > On Mar 26, 8:33 pm, "wolky" <> wrote:
    >
    > > hi all my friends...

    <snip>
    > And for something extra:
    > strstr


    Ooops, I meant: strerror.

    --
    Ioan - Ciprian Tandau
    tandau _at_ freeshell _dot_ org (hope it's not too late)
    (... and that it still works...)
    Nelu, Mar 27, 2007
    #3
  4. wolky

    osmium Guest

    "wolky" <> wrote:


    ý have a problem with file processing in c... ý have some questions
    about it...
    ý have two txt files... in first one there is a text, in second one
    there are words that ý want to remove these words from first one...
    how can ý remove those words from first one?

    Make a third file that is a copy of file 1 without the extraneous words. If
    this is not a student exercise you should prepare by organizing the words so
    you can find them quite rapidly. You could use a tree or bsearch() which
    requires the words be sorted, see qsort(). Both of these are in <stdlib.h>.
    osmium, Mar 27, 2007
    #4
  5. On Mon, 26 Mar 2007 17:33:23 -0700, wolky wrote:

    > hi all my friends...
    > ı have a problem with file processing in c... ı have some questions
    > about it...
    > ı have two txt files... in first one there is a text, in second one
    > there are words that ı want to remove these words from first one... how
    > can ı remove those words from first one?


    Read the first file, producing an ordered binary tree of structs that
    associate each word with its ordinal and any following punctuation.
    Note that you must allow for duplicates words in the first file.

    Create an ordered binary tree of the words in the second file. Whether
    you allow for duplicate words in the second file is between you and
    the specification.

    Traverse both trees in word order, dropping all members of the first
    tree that match words in the second tree.

    Create an array of pointers to the remaining entries in the first tree.
    Use qsort() to sort them by ordinal number.

    Emit the words in the order they appear in the list, each followed by
    the associated punctuation. Dealing with orphaned punctuation and
    post-punctuation capitalization is left as an exercise for the reader.


    > thx all for ur help


    Even the mesopotamians can't help you now.

    Martin
    --
    Martin Golding | He who steals my code steals trash.
    DoD #0236 | (Twas mine, tis his, and will be slave to thousands.)
    A poor old decrepit Pick programmer. Sympathize at:
    Vancouver, WA
    Martin Golding, Mar 28, 2007
    #5
  6. wolky

    CBFalconer Guest

    Martin Golding wrote:
    > On Mon, 26 Mar 2007 17:33:23 -0700, wolky wrote:
    >
    >> ı have a problem with file processing in c... ı have some
    >> questions about it... ı have two txt files... in first one
    >> there is a text, in second one there are words that ı want to
    >> remove these words from first one... how can ı remove those
    >> words from first one?

    >
    > Read the first file, producing an ordered binary tree of structs
    > that associate each word with its ordinal and any following
    > punctuation. Note that you must allow for duplicates words in the
    > first file.

    .... snip ...

    All that work is already done, using a hashtable rather than a key
    (faster), and replacing ids rather than deleting them. Some simple
    modifications will satisfy the OPs needs. Note that it is licensed
    under the GPL. See id2id-20 in:

    <http://cbfalconer.home.att.net/download/>

    Arranging for a successful find of change (in filter) and emission
    of otherword to replace otherword by the empty string will probably
    do it. This is safe because otherword is not involved in the hash
    table comparison or hashing routines. Probably take all of 5
    minutes to edit, make, and test. This will, of course, foul the
    reversing option.

    --
    Chuck F (cbfalconer at maineline dot net)
    Available for consulting/temporary embedded and systems.
    <http://cbfalconer.home.att.net>



    --
    Posted via a free Usenet account from http://www.teranews.com
    CBFalconer, Mar 28, 2007
    #6
    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. Andy
    Replies:
    1
    Views:
    1,367
    Jürgen Exner
    Jan 20, 2004
  2. Maxim
    Replies:
    0
    Views:
    396
    Maxim
    Jul 7, 2003
  3. Long Le
    Replies:
    3
    Views:
    1,160
    Long Le
    Aug 11, 2004
  4. MWells
    Replies:
    2
    Views:
    410
    MWells
    Jan 11, 2005
  5. Hubert Hung-Hsien Chang
    Replies:
    2
    Views:
    410
    Michael Foord
    Sep 17, 2004
Loading...

Share This Page