Re: Can any body tell me how to find duplicate lines in C



RSBakshi@xxxxxxxxx wrote:
> Can any body tell me how to find duplicate lines in C
>
> i have tried to find using Binary tree and Text files but not suceeded
> .
>
> It works for Word but not for lines
>
> please help me
>

Your question isn't really a "C" question, but more an algorithm one.
comp.programming might be a better place to ask it.

Assuming you can slurp the whole file into an array (i.e. assuming
you don't need to work on really big files, etc), you could use
the following simple approach.

1) slurp file into array (look at fgets, or cbfalconer's ggets code)
2) sort the array (look at quicksort)
3) iterate through the array, comparing each line to the next (look at
strcmp)

I expect is a good enough approach. Write some code and come
back with it if you have problems.

> you can write suggetion to my email : rsbakshi@xxxxxxxxx

No thanks, I prefer to post :p

-David

.



Relevant Pages

  • Re: Binary Tree in java(Generic)
    ... Sir,I want to implement it using Array or Link,I mean either a array ... based binary tree or link based.How should I proceed. ... BTW, Lew. ... and change the compareTo method to compare index. ...
    (comp.lang.java.programmer)
  • Re: How to implement an asynchronous timer ?
    ... Heap is an array, no lists are used. ... A heap is a binary tree of elements. ... element associated with the root node with any other element in both ...
    (comp.unix.programmer)
  • Re: memory allocation question
    ... FILE * pFile; ... Calculating the size of the array needed to hold the binary tree will ... > the gap in between. ...
    (alt.comp.lang.learn.c-cpp)
  • binary tree question
    ... given a binary tree is there any way to find the level that contains ... storing the number of nodes on each level. ... is there anyway to do this thing without using that array? ... using a recursive function? ...
    (comp.theory)