If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > plz....help me on this..

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-06-04, 07:21
toyyo toyyo is offline
Registered User
 
Join Date: Oct 2004
Posts: 3
Question plz....help 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............
Reply With Quote
  #2 (permalink)  
Old 11-12-04, 05:51
Filip Poverud Filip Poverud is offline
Registered User
 
Join Date: Oct 2004
Location: Norway
Posts: 53
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

---

/pF
Reply With Quote
  #3 (permalink)  
Old 11-18-04, 21:23
twburger twburger is offline
Registered User
 
Join Date: Nov 2004
Posts: 8
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:

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

begin

// 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);
end;

In C/C++:

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

int result = strncmp(Question, Answer, strlen(Question));
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On