Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2004

    Question Unanswered: me on this..

    hi ....
    i'm designing a program that asks few questions & recieves answers from the user.
    my question is how to compare between the right answer & the user's answer?????????

    i tried to use this statement :
    if (strcmp(answer,user's answer)==0)

    but it seems that it's always false..
    i hope someone help me.....

    thanx anyway............

  2. #2
    Join Date
    Oct 2004
    It would help us if you gave us the version of Delphi you are using, and why you need to do a Case Sensitive comparsion



  3. #3
    Join Date
    Nov 2004
    The reason the strcmp result is always not zero is becuase the strings are always different. The input answer string is probably different from the answer string due to several internal format factors even though they look exactly the same.

    The simple solution is to do a string comparison based on a set length.

    In Delphi:

    answer_string : string;
    question_string : string;
    len : Integer;


    // Set up strings to look the same but not be equal
    question_string := 'hello';
    answer_string := 'hello ';

    // Set the length of the correct answer
    len = Length(question_string);

    // Make the answer string the same as the question
    SetLength(answer_string, len);

    // Compare the strings
    result := AnsiCompareStr(question_string, answer_string);

    In C/C++:

    char *Question = "Hello";
    char *Answer = "Hello ";

    int result = strncmp(Question, Answer, strlen(Question));

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts