string compare
-
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");
-
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");
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.
-
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");
-
You can read both files into two data structure and then compare the two variables. Kuphryn
-
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.
-
yeah.. right! that's what i had in my mind too. but I though '_' has lower ASCII than '0' though. thank you
If you look at an ascii chart, or print their decimal values, "0" = 48 and "_" = 95.
-
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