file processing in c

W

wolky

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
 
N

Nelu

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
 
O

osmium

ý 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>.
 
M

Martin Golding

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
 
C

CBFalconer

Martin said:
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.
 

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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top