Author: Robert Hyatt
Date: 14:58:08 09/11/02
Go up one level in this thread
On September 11, 2002 at 12:45:42, Daniel Clausen wrote:
>On September 11, 2002 at 11:46:39, Robert Hyatt wrote:
>
>>On September 10, 2002 at 23:40:43, scott farrell wrote:
>>
>>>On September 10, 2002 at 12:03:18, Dave Kuntzsch wrote:
>>>
>>>I think this is it - just 1 line:
>>>
>>>printf('resign');
>>
>>More sophisticated, and more complete:
>
>Let's see...
>
>>
>>int main() {
>> char reply[3];
>> printf("I offer a draw\n");
>> scanf("%s",reply);
>
>Using scanf is evil and should be forbidden. If the user enters more than 2
>characters, you have a buffer overflow and anything can happen. (gets() is also
>evil, fgets() is recommended)
>
>
>> if (strcmp(reply,"yes")) printf("I resign\n");
>
>1. You probably mean !strcmp or "strcmp(...) == 0". strcmp() returns 0 if the
>strings are equal, otherwise it returns a positive or a negative number.
>(depending on which string is greater)
No. If he replies "yes" he accepted the draw. I don't resign. :)
If he doesn't reply "yes" then I resign there. again, :)
>
>2. Since 'reply' is defined as an array of 3 chars and strings in C need a '\0'
>for string termination, there's only space for 2 'real' characters.
Correct and a typo on my part. I originally had him entering "no" but
then changed it later. In reality, 2 or 3 would be equally bad...
>
>
>>}
>
>Since main() is supposed to return an int, you should do so.
>
>And of course you forgot to include some headerfiles. But apart from that, it
>should be ok! :)
>
>Sargon
I can survive without the header files since I know how to call scanf and I
didn't refer to any macros or pre-defined data values that the header file
might define. :)
If you are good, you can get away with that.. :)
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.