Author: Daniel Clausen
Date: 09:45:42 09/11/02
Go up one level in this thread
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)
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.
>}
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
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.