Related File Handeling in C lang.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shariquehabib
    New Member
    • Oct 2006
    • 22

    Related File Handeling in C lang.

    Hi All,

    I want to get some values by reading a file (already created) through file handeling but dont want to get DUPLICATE values.

    How can i do that..plz help me out.......

    E.g: file name input.txt having rows like:

    Root 400
    Bye 789
    Teacher 123
    Bye 789

    in output i want to print only :
    Root 400
    Bye 789
    Teacher 123

    Note: Dont want to print duplicate data (Teacher 123)

    If any idea..plz tell me ...with example too.

    --
    Sharique
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    Option 1
    You can use unix utilities instead of C code like this
    cat input.txt | sort -u

    Option 2
    You have to read the data push it to a map or set and then print the map.
    If you can use C++

    Option 3
    You have to write a adata structure which will store uniqe values.


    Raghu

    Comment

    • shariquehabib
      New Member
      • Oct 2006
      • 22

      #3
      Hi Raghu,

      I have to use only C file handeling...i cant change this.
      Can u plz give me small example to select only distinct values from file which we ae opening thru file handeling...

      if possible plz give me peice of prog.

      Thanks,
      Sharique

      Originally posted by gpraghuram
      Option 1
      You can use unix utilities instead of C code like this
      cat input.txt | sort -u

      Option 2
      You have to read the data push it to a map or set and then print the map.
      If you can use C++

      Option 3
      You have to write a adata structure which will store uniqe values.


      Raghu

      Comment

      • gpraghuram
        Recognized Expert Top Contributor
        • Mar 2007
        • 1275

        #4
        If you have to use only C then write a hash list to store the values and before storing check whether the element exists and then store it.
        First start writing the code and if u face issues i can help you out with the problem.
        I cant write the code for you

        Raghu

        Comment

        • shariquehabib
          New Member
          • Oct 2006
          • 22

          #5
          Hi Rahgu,

          I have written this code:

          ::Full code removed, please read Posting Guidelines::

          in that code, how can i avoid duplicate values? i m not aware abt hash list and i have checked with my team mate....i can use only simple file hadeling.

          please help me on this...

          --
          Sharique

          Originally posted by gpraghuram
          If you have to use only C then write a hash list to store the values and before storing check whether the element exists and then store it.
          First start writing the code and if u face issues i can help you out with the problem.
          I cant write the code for you

          Raghu

          Comment

          • shariquehabib
            New Member
            • Oct 2006
            • 22

            #6
            can any one help me on this?

            Comment

            • shariquehabib
              New Member
              • Oct 2006
              • 22

              #7
              Hi Rahgu,

              I have written this code:

              ::Full code removed, please read Posting Guidelines::

              in that code, how can i avoid duplicate values? i m not aware abt hash list and i have checked with my team mate....i can use only simple file hadeling.

              please help me on this...

              --
              Sharique




              Originally posted by gpraghuram
              If you have to use only C then write a hash list to store the values and before storing check whether the element exists and then store it.
              First start writing the code and if u face issues i can help you out with the problem.
              I cant write the code for you

              Raghu

              Comment

              • gpraghuram
                Recognized Expert Top Contributor
                • Mar 2007
                • 1275

                #8
                This is OK.
                But withoput using a data structure you cant get the sorted vales from a file.
                Check whether u can use an array....

                Raghu

                Comment

                • shariquehabib
                  New Member
                  • Oct 2006
                  • 22

                  #9
                  Hi Raghu,

                  But can we avoid duplicates values ( when we are reading from file )??
                  after reading values from file, we can put in array or in stuct.

                  ----
                  Sharique

                  Originally posted by gpraghuram
                  This is OK.
                  But withoput using a data structure you cant get the sorted vales from a file.
                  Check whether u can use an array....

                  Raghu

                  Comment

                  • gpraghuram
                    Recognized Expert Top Contributor
                    • Mar 2007
                    • 1275

                    #10
                    It is not possible to avoid duplicate values while reading.


                    Raghu

                    Comment

                    Working...