Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Comparing lines

Comparing lines

Scheduled Pinned Locked Moved C#
csharphelptutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CodeItWell
    wrote on last edited by
    #1

    I'm working on a program that compares lines from two .txt files line by line. It compares the first line of the first file then first line of the second file and so on. But when the two files have different number of lines the program will fall. How to solve this problem.

    C#

    M C 2 Replies Last reply
    0
    • C CodeItWell

      I'm working on a program that compares lines from two .txt files line by line. It compares the first line of the first file then first line of the second file and so on. But when the two files have different number of lines the program will fall. How to solve this problem.

      C#

      M Offline
      M Offline
      Muammar
      wrote on last edited by
      #2

      You can simply do it by checking the line you get first from the stream before comparing it with what so ever, sorry but not sure how to do it in c#, however you have to look for the "end of file" escape character, we use EOF in c++..

      while(youStreamReader.ReadLine() != EOF)
      dadadadada...

      Another alternative is that you can read the entire file contents once before starting the comparison process and determine the number of lines "using the end of line escape character which you have to find out:)" and use this number in your loop to break it later.. hope this was of some help.


      Smile: A curve that can set a lot of things straight! (\ /) (O.o) (><)

      1 Reply Last reply
      0
      • C CodeItWell

        I'm working on a program that compares lines from two .txt files line by line. It compares the first line of the first file then first line of the second file and so on. But when the two files have different number of lines the program will fall. How to solve this problem.

        C#

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        When two lines do not match, you need to search ahead in both files, to see if either file has a line ahead that matches ( or better matches ) the current one. A brute force approach here is going to be very expensive, I would think.

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups