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 / C++ / MFC
  4. string compare

string compare

Scheduled Pinned Locked Moved C / C++ / MFC
question
7 Posts 4 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.
  • P Offline
    P Offline
    pnpfriend
    wrote on last edited by
    #1

    I uesed all three of strcmp(),CString::CompareNoCase() and CString::Compare() methods. They all give me same answer, that is "Vicki 46_p.txt" is larger than "Vicki 460_p.txt". Why is that? but without using the program and view that tow files in window explore give you different result. if you right click sort by name will give you "Vicki 46_p.txt" on the top. I mean, let's say, I have both files in a: dirve. you go to mycomputer, right click , explore, a:, and then right click, choose arrange icon, by Name. then you will see Vicki 46_p.txt is above of the file name Vicki 46_p.txt. int i = strcmp("Vicki 46_p.txt","Vicki 460_p.txt") ; if(i<0) MessageBox("Vicki 46_p.txt is smaller"); else if(i>0) MessageBox("Vicki 46_p.txt is larger");

    J V 2 Replies Last reply
    0
    • P pnpfriend

      I uesed all three of strcmp(),CString::CompareNoCase() and CString::Compare() methods. They all give me same answer, that is "Vicki 46_p.txt" is larger than "Vicki 460_p.txt". Why is that? but without using the program and view that tow files in window explore give you different result. if you right click sort by name will give you "Vicki 46_p.txt" on the top. I mean, let's say, I have both files in a: dirve. you go to mycomputer, right click , explore, a:, and then right click, choose arrange icon, by Name. then you will see Vicki 46_p.txt is above of the file name Vicki 46_p.txt. int i = strcmp("Vicki 46_p.txt","Vicki 460_p.txt") ; if(i<0) MessageBox("Vicki 46_p.txt is smaller"); else if(i>0) MessageBox("Vicki 46_p.txt is larger");

      J Offline
      J Offline
      jfugate
      wrote on last edited by
      #2

      I believe the way those string compare functions work is to go character by character through the string until one character in the first string is greater or less than the corresponding character in the comparison string. Each character corresponds to an ASCII integer value, which is what the comparison is based on. In your example, both strings are the same up to the 6. At that point, it compares the '_' against the '0'. '0' has a lower ASCII value than '_', so it returns "Vicki 46_p.txt" as greater than "Vicki 460_p.txt". I'm not sure why Explorer sorts them differently. Microsoft probably wrote their own sorting method that parses the strings differently.

      P 1 Reply Last reply
      0
      • P pnpfriend

        I uesed all three of strcmp(),CString::CompareNoCase() and CString::Compare() methods. They all give me same answer, that is "Vicki 46_p.txt" is larger than "Vicki 460_p.txt". Why is that? but without using the program and view that tow files in window explore give you different result. if you right click sort by name will give you "Vicki 46_p.txt" on the top. I mean, let's say, I have both files in a: dirve. you go to mycomputer, right click , explore, a:, and then right click, choose arrange icon, by Name. then you will see Vicki 46_p.txt is above of the file name Vicki 46_p.txt. int i = strcmp("Vicki 46_p.txt","Vicki 460_p.txt") ; if(i<0) MessageBox("Vicki 46_p.txt is smaller"); else if(i>0) MessageBox("Vicki 46_p.txt is larger");

        V Offline
        V Offline
        valikac
        wrote on last edited by
        #3

        You can read both files into two data structure and then compare the two variables. Kuphryn

        P 1 Reply Last reply
        0
        • V valikac

          You can read both files into two data structure and then compare the two variables. Kuphryn

          P Offline
          P Offline
          pnpfriend
          wrote on last edited by
          #4

          two datastructure? what do you mean?

          V 1 Reply Last reply
          0
          • J jfugate

            I believe the way those string compare functions work is to go character by character through the string until one character in the first string is greater or less than the corresponding character in the comparison string. Each character corresponds to an ASCII integer value, which is what the comparison is based on. In your example, both strings are the same up to the 6. At that point, it compares the '_' against the '0'. '0' has a lower ASCII value than '_', so it returns "Vicki 46_p.txt" as greater than "Vicki 460_p.txt". I'm not sure why Explorer sorts them differently. Microsoft probably wrote their own sorting method that parses the strings differently.

            P Offline
            P Offline
            pnpfriend
            wrote on last edited by
            #5

            yeah.. right! that's what i had in my mind too. but I though '_' has lower ASCII than '0' though. thank you

            M 1 Reply Last reply
            0
            • P pnpfriend

              yeah.. right! that's what i had in my mind too. but I though '_' has lower ASCII than '0' though. thank you

              M Offline
              M Offline
              Mel Stober
              wrote on last edited by
              #6

              If you look at an ascii chart, or print their decimal values, "0" = 48 and "_" = 95.

              1 Reply Last reply
              0
              • P pnpfriend

                two datastructure? what do you mean?

                V Offline
                V Offline
                valikac
                wrote on last edited by
                #7

                In terms of data structures, I mean you can store file data into two data structures such as a character array, string, vector, link list and the like. You used strcmp, but then direct the parameter to two files. I am not sure if strcmp can open two files on its owns. Kuphryn

                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