Thread: Help in strcmp

Page 2 of 2 First 12
  • Jump to page:
    #16
  1. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,174
    Rep Power
    2222
    It's your program that is supposed to deal with the unsorted data. When your program finds the need to compare two strings, then it uses strcmp. But you have to write your program.

    Maybe you've been spoiled by some overblown scripting language that does all kinds of extra stuff for you, including tucking you warmly into bed at night. So why don't you just use that instead of C? But one thing I can assure you of: under the hood that overblown scripting language is still comparing pairs of strings.

    If you insist on using C, then use the tools that C gives you! As I already told you, design your program before you even start to try to write any code! Write down exactly what you are trying to do and exactly how you would do it. So far, you have completely failed to even begin to do that! Do you even have any clue what you're trying to accomplish, because you have completely failed to inform us? And if we don't know what you are trying to accomplish, then how could we be able to even begin to help you? You need to compare strings, but what strings, which strings exactly? And then what are you to do based on those comparisons?

    Until you are at the very least able to answer those questions and explain your answer to us so that we can understand it, you're just wasting our time and yours.
  2. #17
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    77
    Rep Power
    0
    Originally Posted by dwise1_aol
    It's your program, you're just wasting our time and yours.
    sorry sir ...
    :chomp: :chomp: :brrr:
  4. #18
  5. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,113
    Rep Power
    1803
    Originally Posted by lhon12006
    can you suggest
    what is the best use in comparing multiple data or to substitute in strcmp in my program ....
    No! You are not listening.
    • You have not clarified the question - it remains unclear what you need to do.
    • You have not posted the code as asked.
    • The link you did post in place of posting code remains broken.


    Programming is about clarity of thought and clear specification of intent. You are exhibiting neither.
  6. #19
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    77
    Rep Power
    0
    sample data format
    the number will change that should i use to compare all data and i want to sort according to Number
    103012031300603130010000010 100000100520267United Kingdom 3031360000011234567890 Joseph Joseph D
    103012031300603130010000010 100000100520261New Jersey 3031360000011234567890 Joseph Joseph D
    103012031300603130010000010 100000100520262United Kingdom 3031360000011234567890 Joseph Joseph D
    103012031300603130010000010 100000100520263United State of America 3031360000011234567890 joseph joseph D
    103012031300603130010000010 100000100520266jakarta 3031360000011234567890 Joseph Joseph D
    103012031300603130010000010 100000100520263india 3031360000011234567890 Joseph Joseph D
    103012031300603130010000010 100000100520266Canada 3031360000011234567890 Mark Mark D
    103012031300603130010000010 100000100520267United State of America 3031360000011234567890 joseph joseph D
    103012031300603130010000010 100000100520267United State of America 3031360000011234567890 joseph joseph D
    |Date| |Number |Address | |ID# | |Lname |Fname |Minit


    this my actual code

    void BlockReadWrite(FILE *fin, FILE *fout){ ///// REPORT
    int num;
    char buff[MAX_LEN +1];
    ctr = 0;
    Amt1 = 0;
    acct[0] = NULL;
    if (fin != NULL){
    while(!feof(fin)){
    num = fread(buff, sizeof(char ), MAX_LEN, fin);
    buff[num * sizeof(char )] = '\0';
    if (strcmp(TranDate, dated1)== 0){ // date would be 0-6
    substring(37, 47, buff, Number, sizeof Number); //Number
    substring(47, 79, buff, Address, sizeof Address); //Address
    substring(92, 102, buff, Id#, sizeof Id#); //Id#
    substring(110, 122, buff, LName, sizeof LName); //LName
    substring(131, 142, buff, FName, sizeof FName); //FName
    substring(143, 144, buff, MInit, sizeof MInit); //MInit
    substring(78, 92, buff, data, sizeof data); //Data

    if (strcmp(acct, Number) != 0){ // use the strcmp to compare
    if (acct[0] == NULL) {
    Heading(); // Display Header
    SubHead(); // display sub header
    }
    else {
    MFooter(); // display footer
    printf("\n\n");
    SubHead(); // display subfooter
    }
    strcpy(acct, AcctNo);
    ctr++;
    }
    fprintf(fptr1," %s%s%s %s %s",Id#,LName,FName,MInit,Data);
    }
    }
    fclose(fin);
    }
    }

    Comments on this post

    • ptr2void disagrees : When the HELL are you going to learn to use code tags???
  8. #20
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    77
    Rep Power
    0
    sory

    Code:
    void BlockReadWrite(FILE *fin, FILE *fout){ ///// REPORT
    int num;
    char buff[MAX_LEN +1];
    ctr = 0;
    Amt1 = 0;
    acct[0] = NULL;
    if (fin != NULL){
        while(!feof(fin)){
            num = fread(buff, sizeof(char ), MAX_LEN, fin);
            buff[num * sizeof(char )] = '\0';
                if (strcmp(TranDate, dated1)== 0){ // date would be 0-6
                    substring(37, 47, buff, Number, sizeof Number); //Number
                    substring(47, 79, buff, Address, sizeof Address); //Address
                    substring(92, 102, buff, Id#, sizeof Id#); //Id#
                    substring(110, 122, buff, LName, sizeof LName); //LName
                    substring(131, 142, buff, FName, sizeof FName); //FName
                    substring(143, 144, buff, MInit, sizeof MInit); //MInit
                    substring(78, 92, buff, data, sizeof data); //Data
    
                    if (strcmp(acct, Number) != 0){ // use the strcmp to compare
                        if (acct[0] == NULL) {
                            Heading(); // Display Header
                            SubHead(); // display sub header
                        }
                        else {
                            MFooter(); // display footer
                            printf("\n\n");
                            SubHead(); // display subfooter
                        }
                        strcpy(acct, AcctNo);
                        ctr++;
                    }
                    fprintf(fptr1," %s%s%s %s %s",Id#,LName,FName,MInit,Data);
                }
            }
            fclose(fin);
        }
    }
  10. #21
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    77
    Rep Power
    0
    :tntworth: :tntworth:

    please
    help me modify my project please .....

    :brrr: :brrr:
  12. #22
  13. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,392
    Rep Power
    1871
    Why are you reading the file using fread?
    That only makes sense if you have fixed length records, but you don't.
    Code:
    $ xsel | awk '{ print length,$0 }'
    96 103012031300603130010000010 100000100520267United Kingdom 3031360000011234567890 Joseph Joseph D
    92 103012031300603130010000010 100000100520261New Jersey 3031360000011234567890 Joseph Joseph D
    96 103012031300603130010000010 100000100520262United Kingdom 3031360000011234567890 Joseph Joseph D
    105 103012031300603130010000010 100000100520263United State of America 3031360000011234567890 joseph joseph D
    89 103012031300603130010000010 100000100520266jakarta 3031360000011234567890 Joseph Joseph D
    87 103012031300603130010000010 100000100520263india 3031360000011234567890 Joseph Joseph D
    84 103012031300603130010000010 100000100520266Canada 3031360000011234567890 Mark Mark D
    105 103012031300603130010000010 100000100520267United State of America 3031360000011234567890 joseph joseph D
    105 103012031300603130010000010 100000100520267United State of America 3031360000011234567890 joseph joseph D
    You have record lengths between 84 and 105 characters.

    So if your buffer were 100 characters say, you would read the whole of record 1, AND 4 characters of record 2.
    Then the fun really starts, you then read all of record 2 AND 12 chars of record 3.

    And so it goes on, getting increasingly screwed up.

    If you really have variable length text lines, then use fgets
    Code:
    while ( fgets( buff, sizeof(buff), fin ) != NULL ) {
        // No idea where you got this from, but it's your code
        if (strcmp(TranDate, dated1)== 0) {
        }
    }
    Also, being variable length, you can't just substring() everything out of it. You need to do some actual parsing as well.

    Unless of course the post of your actual data was as badly screwed up as your code, and lots of spaces to create the fixed width data requirement were lost in your post.
    Already, I'm regretting replying to this :(
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  14. #23
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    77
    Rep Power
    0
    sorry sir this would be the actual data source

    Code:
    
    103012031300603130010000010 100000100520267United Kingdom          3031360000011234567890 Joseph Joseph D
    103012031300603130010000010 100000100520261New Jersey              3031360000011234567890 Joseph Joseph D
    103012031300603130010000010 100000100520262United Kingdom          3031360000011234567890 Joseph Joseph D
    103012031300603130010000010 100000100520263United State of America 3031360000011234567890 joseph joseph D
    103012031300603130010000010 100000100520266jakarta                 3031360000011234567890 Joseph Joseph D
    103012031300603130010000010 100000100520263india                   3031360000011234567890 Joseph Joseph D
    103012031300603130010000010 100000100520266Canada                  3031360000011234567890 Mark   Mark   D
    103012031300603130010000010 100000100520267United State of America 3031360000011234567890 joseph joseph D
    103012031300603130010000010 100000100520267United State of America 3031360000011234567890 joseph joseph D
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo