A<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2FString%2FString_General</id>
		<title>C/String/String General - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2FString%2FString_General"/>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C/String/String_General&amp;action=history"/>
		<updated>2026-04-18T00:03:29Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C/String/String_General&amp;diff=138&amp;oldid=prev</id>
		<title> в 14:20, 25 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C/String/String_General&amp;diff=138&amp;oldid=prev"/>
				<updated>2010-05-25T14:20:56Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 14:20, 25 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C/String/String_General&amp;diff=139&amp;oldid=prev</id>
		<title>Admin: 1 версия:&amp;#32;Импорт контента...</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C/String/String_General&amp;diff=139&amp;oldid=prev"/>
				<updated>2010-05-25T10:22:17Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия: Импорт контента...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==A function to read a string terminated by an arbitrary character==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#define MAX_SIZE     100&lt;br /&gt;
&lt;br /&gt;
char* getString(char *buffer, char end_char);&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  char buffer[MAX_SIZE];&lt;br /&gt;
  int i = 0;&lt;br /&gt;
  printf(&amp;quot;Enter a string terminated by a semi-colon:\n&amp;quot;);&lt;br /&gt;
  getString(buffer, &amp;quot;;&amp;quot;);&lt;br /&gt;
  printf(&amp;quot;:\n%s\n&amp;quot;, buffer);&lt;br /&gt;
}&lt;br /&gt;
char* getString(char *buffer, char end_char)&lt;br /&gt;
{&lt;br /&gt;
  size_t i = 0;&lt;br /&gt;
  /* Read a character until end_char is entered */&lt;br /&gt;
  while((buffer[i++] = getchar()) != end_char)&lt;br /&gt;
    ;&lt;br /&gt;
  buffer[i-1] = &amp;quot;\0&amp;quot;;  /* Overwrite end_char with string terminator */&lt;br /&gt;
  return buffer;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Analyze comma-separated list of words==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  char list[5000]=&amp;quot;This, is, a, test.&amp;quot;;&lt;br /&gt;
  char words[500][20];&lt;br /&gt;
  const char comma = &amp;quot;,&amp;quot;;&lt;br /&gt;
  const char space = &amp;quot; &amp;quot;;&lt;br /&gt;
  int count = 0;&lt;br /&gt;
  int word_length = 0;&lt;br /&gt;
  int i = 0;&lt;br /&gt;
  while(list[i] != &amp;quot;\0&amp;quot;)&lt;br /&gt;
  {&lt;br /&gt;
    /* Skip over spaces and commas */&lt;br /&gt;
    while(list[i] == space || list[i] == comma)&lt;br /&gt;
      ++i;&lt;br /&gt;
    /* Copy characters that are not space, comma or \0 as part of a word */&lt;br /&gt;
    while(list[i] != space &amp;amp;&amp;amp; list[i] != comma &amp;amp;&amp;amp; list[i] != &amp;quot;\0&amp;quot;)&lt;br /&gt;
     words[count][word_length++] = list[i++];&lt;br /&gt;
    words[count++][word_length] = &amp;quot;\0&amp;quot;;  /* Append terminator         */&lt;br /&gt;
    word_length = 0;&lt;br /&gt;
  }&lt;br /&gt;
  printf(&amp;quot;\nThe words in the list are:\n&amp;quot;);&lt;br /&gt;
  for(i = 0 ; i&amp;lt;count ; i++)&lt;br /&gt;
    printf(&amp;quot;%s\n&amp;quot;,words[i]);&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Arrays of Pointers to Strings==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#define BUFFER_LEN 500&lt;br /&gt;
int main() {&lt;br /&gt;
   char buffer[BUFFER_LEN];&lt;br /&gt;
   char *pS[3] = { NULL };&lt;br /&gt;
   char *pbuffer = buffer;&lt;br /&gt;
   int i = 0;&lt;br /&gt;
   for (i=0; i&amp;lt;3 ; i++)&lt;br /&gt;
   {&lt;br /&gt;
     printf(&amp;quot;\nEnter a message\n&amp;quot;);&lt;br /&gt;
     *(pS + i) = pbuffer;    &lt;br /&gt;
     /* Get input till Enter pressed */&lt;br /&gt;
     while ((*pbuffer++ = getchar()) != &amp;quot;\n&amp;quot;);&lt;br /&gt;
     *(pbuffer - 1) = &amp;quot;\0&amp;quot;;&lt;br /&gt;
   }&lt;br /&gt;
   printf(&amp;quot;\nThe strings you entered are:\n\n&amp;quot;);&lt;br /&gt;
   for(i = 0 ; i&amp;lt;3 ; i++)&lt;br /&gt;
     printf(&amp;quot;%s\n&amp;quot;, *(pS+i));&lt;br /&gt;
   printf(&amp;quot;The buffer has %d characters unused.\n&amp;quot;,&amp;amp;buffer[BUFFER_LEN - 1] - pbuffer + 1);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Function: Sort string ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#define TRUE  1&lt;br /&gt;
#define FALSE 0&lt;br /&gt;
void str_sort(char *[], int);&lt;br /&gt;
void str_out(char *[], int);&lt;br /&gt;
#define BUFFER_LEN 240&lt;br /&gt;
#define NUM_P 50&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   char *pS[NUM_P];&lt;br /&gt;
   int count = 3;&lt;br /&gt;
   int i = 0;                /* Loop counter               */&lt;br /&gt;
   pS[0] = &amp;quot;A&amp;quot;;&lt;br /&gt;
   pS[1] = &amp;quot;C&amp;quot;;&lt;br /&gt;
   pS[2] = &amp;quot;B&amp;quot;;&lt;br /&gt;
   str_sort( pS, count );&lt;br /&gt;
   printf(&amp;quot;\nYour input sorted in order is:\n\n&amp;quot;);&lt;br /&gt;
   for (i = 0 ; i&amp;lt;count ; i++)&lt;br /&gt;
   {&lt;br /&gt;
     printf(&amp;quot;%s\n&amp;quot;, pS[i]);   /* Display a string           */&lt;br /&gt;
     free(pS[i]);             /* Free memory for the string */&lt;br /&gt;
     pS[i] = NULL;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
void str_sort(char *p[], int n)&lt;br /&gt;
{&lt;br /&gt;
   char *pTemp = NULL;&lt;br /&gt;
   int i = 0;&lt;br /&gt;
   int sorted = FALSE;&lt;br /&gt;
   while(!sorted)&lt;br /&gt;
   {&lt;br /&gt;
     sorted = TRUE;&lt;br /&gt;
     for( i = 0 ; i&amp;lt;n-1 ; i++ )&lt;br /&gt;
       if(strcmp(p[i], p[i + 1]) &amp;gt; 0)&lt;br /&gt;
       {&lt;br /&gt;
         sorted = FALSE;&lt;br /&gt;
         pTemp= p[i];&lt;br /&gt;
         p[i] = p[i + 1];&lt;br /&gt;
         p[i + 1]  = pTemp;&lt;br /&gt;
       }&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==How to copy a string==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
  char str[5];&lt;br /&gt;
  strcpy(str, &amp;quot;this is a test&amp;quot;);&lt;br /&gt;
  printf(str);&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Looking for palindromes==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ctype.h&amp;gt;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
  char sentence_chars[500] =&amp;quot;level&amp;quot;;&lt;br /&gt;
  int i = 0;&lt;br /&gt;
  int j = 0;&lt;br /&gt;
  int length = 0;&lt;br /&gt;
  length = strlen(sentence_chars);&lt;br /&gt;
  for(i = 0 ; i&amp;lt;length/2 ; i++){&lt;br /&gt;
    if(sentence_chars[i] != sentence_chars[length-1-i])&lt;br /&gt;
    {&lt;br /&gt;
      printf(&amp;quot;\n The sentence you entered is not a palindrome.\n&amp;quot;);&lt;br /&gt;
      break;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Managing memory and storing strings==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#define BUFFER_LEN 500&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   char buffer[BUFFER_LEN];  /* Store for strings        */&lt;br /&gt;
   char *pS1 = NULL;         /* Pointer to first string  */&lt;br /&gt;
   char *pS2 = NULL;         /* Pointer to second string */&lt;br /&gt;
   char *pS3 = NULL;         /* Pointer to third string  */&lt;br /&gt;
   char *pbuffer = buffer;   /* Pointer to buffer        */&lt;br /&gt;
   printf(&amp;quot;\nEnter a message\n&amp;quot;);&lt;br /&gt;
   pS1 = pbuffer;&lt;br /&gt;
   while ((*pbuffer++ = getchar()) != &amp;quot;\n&amp;quot;);&lt;br /&gt;
   *(pbuffer - 1) = &amp;quot;\0&amp;quot;;&lt;br /&gt;
   printf(&amp;quot;\nEnter another message\n&amp;quot;);&lt;br /&gt;
   pS2 = pbuffer;&lt;br /&gt;
   while ((*pbuffer++ = getchar()) != &amp;quot;\n&amp;quot;);&lt;br /&gt;
   *(pbuffer - 1) = &amp;quot;\0&amp;quot;;&lt;br /&gt;
   printf(&amp;quot;\nEnter another message\n&amp;quot;);&lt;br /&gt;
   pS3 = pbuffer;&lt;br /&gt;
   while((*pbuffer++ = getchar()) != &amp;quot;\n&amp;quot;);&lt;br /&gt;
   *(pbuffer - 1) = &amp;quot;\0&amp;quot;;&lt;br /&gt;
   printf(&amp;quot;\nThe strings you entered are:\n\n%s\n%s\n%s&amp;quot;,pS1, pS2, pS3);&lt;br /&gt;
   printf(&amp;quot;\nThe buffer has %d characters unused.\n&amp;quot;,&amp;amp;buffer[BUFFER_LEN - 1] - pbuffer + 1);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Output a name and address==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
  /* The double quotes must appear as the escape sequence \&amp;quot; */&lt;br /&gt;
  printf(&amp;quot;\n\&amp;quot;It&amp;quot;s freezing in here,\&amp;quot; he said coldly.\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Output a name and address 2==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
  printf(&amp;quot;\nGeorge Washington&amp;quot;);&lt;br /&gt;
  printf(&amp;quot;\n3200 George Washington Memorial Parkway&amp;quot;);&lt;br /&gt;
  printf(&amp;quot;\nMount Vernon&amp;quot;);&lt;br /&gt;
  printf(&amp;quot;\nVirginia 22121\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Output a name and address in a single statement==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
void main() {&lt;br /&gt;
  /* The compiler will automatically join strings together into &lt;br /&gt;
     a single string when they immediately follow one another   */&lt;br /&gt;
  printf(&amp;quot;\nGeorge Washington&amp;quot;&lt;br /&gt;
         &amp;quot;\n3200 George Washington Memorial Parkway&amp;quot;&lt;br /&gt;
         &amp;quot;\nMount Vernon\nVirginia 22121\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Output string==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
  printf(&amp;quot;%s %s %s&amp;quot;, &amp;quot;1&amp;quot;, &amp;quot;2&amp;quot;, &amp;quot;3&amp;quot;);&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Reading a string with gets()==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
  char initial[2] = { 0 };&lt;br /&gt;
  char name[80] = { 0 };&lt;br /&gt;
  printf(&amp;quot;Your first initial: &amp;quot;);&lt;br /&gt;
  gets(initial);&lt;br /&gt;
  &lt;br /&gt;
  printf(&amp;quot;Your name: &amp;quot; );&lt;br /&gt;
  gets(name);&lt;br /&gt;
  &lt;br /&gt;
  if(initial[0] != name[0])&lt;br /&gt;
      printf(&amp;quot;\n%s,you got your initial wrong.\n&amp;quot;, name);&lt;br /&gt;
  else&lt;br /&gt;
      printf(&amp;quot;\nHi, %s. Your initial is correct. Well done!\n&amp;quot;, name);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Removing spaces and puctuation from a string==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ctype.h&amp;gt;&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
   char buffer[80] = &amp;quot;This is a test&amp;quot;;&lt;br /&gt;
   char *pbuffer1 = buffer;&lt;br /&gt;
   char *pbuffer2 = buffer;&lt;br /&gt;
   pbuffer1 = buffer;              /* Reset pointer to start           */&lt;br /&gt;
   while(*pbuffer1 != &amp;quot;\0&amp;quot;)&lt;br /&gt;
   {&lt;br /&gt;
     if(ispunct(*pbuffer1) || isspace(*pbuffer1))&lt;br /&gt;
     {&lt;br /&gt;
       ++pbuffer1;&lt;br /&gt;
       continue;&lt;br /&gt;
     }&lt;br /&gt;
     else&lt;br /&gt;
       *pbuffer2++ = *pbuffer1++;  /* otherwise, copy the character */&lt;br /&gt;
   }&lt;br /&gt;
   *pbuffer2 = &amp;quot;\0&amp;quot;;               /* Append string terminator      */&lt;br /&gt;
   printf(&amp;quot;\n%s\n&amp;quot;, buffer);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==REVERSI An Othello type game==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Beginning C, Third Edition&lt;br /&gt;
 By Ivor Horton&lt;br /&gt;
 ISBN: 1-59059-253-0&lt;br /&gt;
 Published: Apr 2004&lt;br /&gt;
 Publisher: apress&lt;br /&gt;
*/&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ctype.h&amp;gt;&lt;br /&gt;
#define SIZE 6  /* Board size - must be even */&lt;br /&gt;
/* Function prototypes */&lt;br /&gt;
void display(char board[][SIZE]);&lt;br /&gt;
int valid_moves(char board[][SIZE], int moves[][SIZE], char player); &lt;br /&gt;
void make_move(char board[][SIZE], int row, int col, char player);  &lt;br /&gt;
void computer_move(char board[][SIZE], int moves[][SIZE], char player);  &lt;br /&gt;
int best_move(char board[][SIZE], int moves[][SIZE], char player);&lt;br /&gt;
int get_score(char board[][SIZE], char player);&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
  char board [SIZE][SIZE] = { 0 };  /* The board           */&lt;br /&gt;
  int moves[SIZE][SIZE] = { 0 };    /* Valid moves         */&lt;br /&gt;
  int row = 0;                      /* Board row index     */&lt;br /&gt;
  int col = 0;                      /* Board column index  */&lt;br /&gt;
  int no_of_games = 0;              /* Number of games     */&lt;br /&gt;
  int no_of_moves = 0;              /* Count of moves      */&lt;br /&gt;
  int invalid_moves = 0;            /* Invalid move count  */&lt;br /&gt;
  int comp_score = 0;               /* Computer score      */&lt;br /&gt;
  int user_score = 0;               /* Player score        */&lt;br /&gt;
  char y = 0;                       /* Column letter       */&lt;br /&gt;
  int x = 0;                        /* Row number          */&lt;br /&gt;
  char again = 0;                   /* Replay choice input */&lt;br /&gt;
  int player = 0;                   /* Player indicator    */&lt;br /&gt;
   printf(&amp;quot;\nREVERSI\n\n&amp;quot;);&lt;br /&gt;
  printf(&amp;quot;You can go first on the first game, then we will take turns.\n&amp;quot;);&lt;br /&gt;
  printf(&amp;quot;   You will be white - (O)\n   I will be black   - (@).\n&amp;quot;);&lt;br /&gt;
  printf(&amp;quot;Select a square for your move by typing a digit for the row\n &amp;quot;&lt;br /&gt;
    &amp;quot;and a letter for the column with no spaces between.\n&amp;quot;);&lt;br /&gt;
  printf(&amp;quot;\nGood luck!  Press Enter to start.\n&amp;quot;);&lt;br /&gt;
  scanf(&amp;quot;%c&amp;quot;, &amp;amp;again);&lt;br /&gt;
   /* Prompt for how to play - as before */&lt;br /&gt;
   /* The main game loop */&lt;br /&gt;
   do&lt;br /&gt;
   {&lt;br /&gt;
     /* On even games the player starts; */&lt;br /&gt;
     /* on odd games the computer starts */&lt;br /&gt;
     player = ++no_of_games % 2; &lt;br /&gt;
     no_of_moves = 4;                /* Starts with four counters */&lt;br /&gt;
     /* Blank all the board squares */    &lt;br /&gt;
     for(row = 0; row &amp;lt; SIZE; row++)&lt;br /&gt;
       for(col = 0; col &amp;lt; SIZE; col++)&lt;br /&gt;
         board[row][col] = &amp;quot; &amp;quot;;&lt;br /&gt;
     /* Place the initial four counters in the center */&lt;br /&gt;
     board[SIZE/2 - 1][SIZE/2 - 1] = board[SIZE/2][SIZE/2] = &amp;quot;O&amp;quot;;&lt;br /&gt;
     board[SIZE/2 - 1][SIZE/2] = board[SIZE/2][SIZE/2 - 1] = &amp;quot;@&amp;quot;;&lt;br /&gt;
     /* The game play loop */&lt;br /&gt;
     do&lt;br /&gt;
     {&lt;br /&gt;
       display(board);             /* Display the board  */&lt;br /&gt;
       if(player++ % 2)&lt;br /&gt;
       { /*   It is the player&amp;quot;s turn                    */&lt;br /&gt;
         if(valid_moves(board, moves, &amp;quot;O&amp;quot;))&lt;br /&gt;
         {&lt;br /&gt;
           /* Read player moves until a valid move is entered */&lt;br /&gt;
           for(;;)&lt;br /&gt;
           {&lt;br /&gt;
             fflush(stdin);              /* Flush the keyboard buffer */&lt;br /&gt;
             printf(&amp;quot;Please enter your move (row column): &amp;quot;); &lt;br /&gt;
             scanf(&amp;quot;%d%c&amp;quot;, &amp;amp;x, &amp;amp;y);              /* Read input        */&lt;br /&gt;
             y = tolower(y) - &amp;quot;a&amp;quot;;         /* Convert to column index */&lt;br /&gt;
             x--;                          /* Convert to row index    */&lt;br /&gt;
             if( x&amp;gt;=0 &amp;amp;&amp;amp; y&amp;gt;=0 &amp;amp;&amp;amp; x&amp;lt;SIZE &amp;amp;&amp;amp; y&amp;lt;SIZE &amp;amp;&amp;amp; moves[x][y])&lt;br /&gt;
             {&lt;br /&gt;
               make_move(board, x, y, &amp;quot;O&amp;quot;);&lt;br /&gt;
               no_of_moves++;              /* Increment move count */&lt;br /&gt;
               break;&lt;br /&gt;
             }&lt;br /&gt;
             else&lt;br /&gt;
               printf(&amp;quot;Not a valid move, try again.\n&amp;quot;);&lt;br /&gt;
           }&lt;br /&gt;
         }&lt;br /&gt;
         else                              /* No valid moves */&lt;br /&gt;
           if(++invalid_moves&amp;lt;2)&lt;br /&gt;
           {&lt;br /&gt;
             fflush(stdin);&lt;br /&gt;
             printf(&amp;quot;\nYou have to pass, press return&amp;quot;);&lt;br /&gt;
             scanf(&amp;quot;%c&amp;quot;, &amp;amp;again);&lt;br /&gt;
           }&lt;br /&gt;
           else&lt;br /&gt;
             printf(&amp;quot;\nNeither of us can go, so the game is over.\n&amp;quot;);&lt;br /&gt;
       }&lt;br /&gt;
       else&lt;br /&gt;
       { /* It is the computer&amp;quot;s turn                    */&lt;br /&gt;
         if(valid_moves(board, moves, &amp;quot;@&amp;quot;)) /* Check for valid moves */&lt;br /&gt;
         {&lt;br /&gt;
           invalid_moves = 0;               /* Reset invalid count   */&lt;br /&gt;
           computer_move(board, moves, &amp;quot;@&amp;quot;);&lt;br /&gt;
           no_of_moves++;                   /* Increment move count  */&lt;br /&gt;
         }&lt;br /&gt;
         else&lt;br /&gt;
         {&lt;br /&gt;
           if(++invalid_moves&amp;lt;2)&lt;br /&gt;
             printf(&amp;quot;\nI have to pass, your go\n&amp;quot;); /* No valid move */&lt;br /&gt;
           else&lt;br /&gt;
             printf(&amp;quot;\nNeither of us can go, so the game is over.\n&amp;quot;);&lt;br /&gt;
         }&lt;br /&gt;
       }&lt;br /&gt;
     }while(no_of_moves &amp;lt; SIZE*SIZE &amp;amp;&amp;amp; invalid_moves&amp;lt;2);&lt;br /&gt;
     /* Game is over */&lt;br /&gt;
     display(board);  /* Show final board */&lt;br /&gt;
     /* Get final scores and display them */&lt;br /&gt;
     comp_score = user_score = 0; &lt;br /&gt;
     for(row = 0; row &amp;lt; SIZE; row++)&lt;br /&gt;
       for(col = 0; col &amp;lt; SIZE; col++)&lt;br /&gt;
       {&lt;br /&gt;
         comp_score += board[row][col] == &amp;quot;@&amp;quot;;&lt;br /&gt;
         user_score += board[row][col] == &amp;quot;O&amp;quot;;&lt;br /&gt;
       }&lt;br /&gt;
     printf(&amp;quot;The final score is:\n&amp;quot;);&lt;br /&gt;
     printf(&amp;quot;Computer %d\n    User %d\n\n&amp;quot;, comp_score, user_score);&lt;br /&gt;
     fflush(stdin);               /* Flush the input buffer */&lt;br /&gt;
     printf(&amp;quot;Do you want to play again (y/n): &amp;quot;);&lt;br /&gt;
     scanf(&amp;quot;%c&amp;quot;, &amp;amp;again);         /* Get y or n             */&lt;br /&gt;
   }while(tolower(again) == &amp;quot;y&amp;quot;); /* Go again on y          */&lt;br /&gt;
   printf(&amp;quot;\nGoodbye\n&amp;quot;); &lt;br /&gt;
}&lt;br /&gt;
/***********************************************&lt;br /&gt;
 * Function to display the board in it&amp;quot;s       *&lt;br /&gt;
 * current state with row numbers and column   *&lt;br /&gt;
 * letters to identify squares.                *&lt;br /&gt;
 * Parameter is the board array.               *&lt;br /&gt;
 ***********************************************/&lt;br /&gt;
void display(char board[][SIZE])&lt;br /&gt;
{&lt;br /&gt;
   int row  = 0;          /* Row index      */&lt;br /&gt;
   int col = 0;           /* Column index   */&lt;br /&gt;
   char col_label = &amp;quot;a&amp;quot;;  /* Column label   */&lt;br /&gt;
   printf(&amp;quot;\n &amp;quot;);         /* Start top line */&lt;br /&gt;
   for(col = 0 ; col&amp;lt;SIZE ;col++)&lt;br /&gt;
     printf(&amp;quot;   %c&amp;quot;, col_label+col); /* Display the top line */&lt;br /&gt;
   printf(&amp;quot;\n&amp;quot;);                     /* End the top line     */&lt;br /&gt;
   /* Display the intermediate rows */  &lt;br /&gt;
   for(row = 0; row &amp;lt; SIZE; row++)&lt;br /&gt;
   {&lt;br /&gt;
     printf(&amp;quot;  +&amp;quot;);&lt;br /&gt;
     for(col = 0; col&amp;lt;SIZE; col++)&lt;br /&gt;
       printf(&amp;quot;---+&amp;quot;);&lt;br /&gt;
     printf(&amp;quot;\n%2d|&amp;quot;,row + 1); &lt;br /&gt;
     for(col = 0; col&amp;lt;SIZE; col++)&lt;br /&gt;
       printf(&amp;quot; %c |&amp;quot;, board[row][col]);  /* Display counters in row */&lt;br /&gt;
     printf(&amp;quot;\n&amp;quot;);    &lt;br /&gt;
   }&lt;br /&gt;
   printf(&amp;quot;  +&amp;quot;);                  /* Start the bottom line   */&lt;br /&gt;
   for(col = 0 ; col&amp;lt;SIZE ;col++)&lt;br /&gt;
     printf(&amp;quot;---+&amp;quot;);               /* Display the bottom line */&lt;br /&gt;
   printf(&amp;quot;\n&amp;quot;);                   /* End the bottom  line    */&lt;br /&gt;
}&lt;br /&gt;
/***********************************************&lt;br /&gt;
/* Calculates which squares are valid moves    *&lt;br /&gt;
 * for player. Valid moves are recorded in the *&lt;br /&gt;
 * moves array - 1 indicates a valid move,     *&lt;br /&gt;
 * 0 indicates an invalid move.                *&lt;br /&gt;
 * First parameter is the board array          *&lt;br /&gt;
 * Second parameter is the moves array         *&lt;br /&gt;
 * Third parameter identifies the player       *&lt;br /&gt;
 * to make the move.                           *&lt;br /&gt;
 * Returns valid move count.                   *&lt;br /&gt;
 ***********************************************/&lt;br /&gt;
int valid_moves(char board[][SIZE], int moves[][SIZE], char player)&lt;br /&gt;
{&lt;br /&gt;
   int rowdelta = 0;     /* Row increment around a square    */&lt;br /&gt;
   int coldelta = 0;     /* Column increment around a square */&lt;br /&gt;
   int row = 0;          /* Row index                        */&lt;br /&gt;
   int col = 0;          /* Column index                     */&lt;br /&gt;
   int x = 0;            /* Row index when searching         */&lt;br /&gt;
   int y = 0;            /* Column index when searching      */&lt;br /&gt;
   int no_of_moves = 0;  /* Number of valid moves            */&lt;br /&gt;
   /* Set the opponent            */&lt;br /&gt;
   char opponent = (player == &amp;quot;O&amp;quot;)? &amp;quot;@&amp;quot; : &amp;quot;O&amp;quot;;    &lt;br /&gt;
   /* Initialize moves array to zero */&lt;br /&gt;
   for(row = 0; row &amp;lt; SIZE; row++)&lt;br /&gt;
     for(col = 0; col &amp;lt; SIZE; col++)&lt;br /&gt;
       moves[row][col] = 0;&lt;br /&gt;
   /* Find squares for valid moves.                           */&lt;br /&gt;
   /* A valid move must be on a blank square and must enclose */&lt;br /&gt;
   /* at least one opponent square between two player squares */&lt;br /&gt;
   for(row = 0; row &amp;lt; SIZE; row++)&lt;br /&gt;
     for(col = 0; col &amp;lt; SIZE; col++)&lt;br /&gt;
     {&lt;br /&gt;
       if(board[row][col] != &amp;quot; &amp;quot;)   /* Is it a blank square?  */&lt;br /&gt;
         continue;                  /* No - so on to the next */&lt;br /&gt;
       /* Check all the squares around the blank square  */ &lt;br /&gt;
       /* for the opponents counter                      */&lt;br /&gt;
       for(rowdelta = -1; rowdelta &amp;lt;= 1; rowdelta++)&lt;br /&gt;
         for(coldelta = -1; coldelta &amp;lt;= 1; coldelta++)&lt;br /&gt;
         { &lt;br /&gt;
           /* Don&amp;quot;t check outside the array, or the current square */&lt;br /&gt;
           if(row + rowdelta &amp;lt; 0 || row + rowdelta &amp;gt;= SIZE ||&lt;br /&gt;
              col + coldelta &amp;lt; 0 || col + coldelta &amp;gt;= SIZE || &lt;br /&gt;
                                       (rowdelta==0 &amp;amp;&amp;amp; coldelta==0))&lt;br /&gt;
             continue;&lt;br /&gt;
           /* Now check the square */&lt;br /&gt;
           if(board[row + rowdelta][col + coldelta] == opponent)&lt;br /&gt;
           {&lt;br /&gt;
             /* If we find the opponent, move in the delta direction  */&lt;br /&gt;
             /* over opponent counters searching for a player counter */&lt;br /&gt;
             x = row + rowdelta;                /* Move to          */&lt;br /&gt;
             y = col + coldelta;                /* opponent square  */&lt;br /&gt;
             /* Look for a player square in the delta direction */&lt;br /&gt;
             for(;;)&lt;br /&gt;
             {&lt;br /&gt;
               x += rowdelta;                  /* Go to next square */&lt;br /&gt;
               y += coldelta;                  /* in delta direction*/&lt;br /&gt;
               /* If we move outside the array, give up */&lt;br /&gt;
               if(x &amp;lt; 0 || x &amp;gt;= SIZE || y &amp;lt; 0 || y &amp;gt;= SIZE)&lt;br /&gt;
                 break;&lt;br /&gt;
               /* If we find a blank square, give up */ &lt;br /&gt;
               if(board[x][y] == &amp;quot; &amp;quot;)&lt;br /&gt;
                 break;&lt;br /&gt;
                /*  If the square has a player counter */&lt;br /&gt;
                /*  then we have a valid move          */&lt;br /&gt;
               if(board[x][y] == player)&lt;br /&gt;
               {&lt;br /&gt;
                 moves[row][col] = 1;   /* Mark as valid */&lt;br /&gt;
                 no_of_moves++;         /* Increase valid moves count */&lt;br /&gt;
                 break;                 /* Go check another square    */&lt;br /&gt;
               }&lt;br /&gt;
             } &lt;br /&gt;
           } &lt;br /&gt;
         }  &lt;br /&gt;
     }&lt;br /&gt;
   return no_of_moves; &lt;br /&gt;
}&lt;br /&gt;
/************&lt;br /&gt;
 * Finds the best move for the computer. This is the move for      *&lt;br /&gt;
 * which the opponent&amp;quot;s best possible move score is a minimum.     *&lt;br /&gt;
 * First parameter is the board array.                             *&lt;br /&gt;
 * Second parameter is the moves array containing valid moves.     *&lt;br /&gt;
 * Third parameter identifies the computer.                        *&lt;br /&gt;
 ************/&lt;br /&gt;
void computer_move(char board[][SIZE], int moves[][SIZE], char player)&lt;br /&gt;
{&lt;br /&gt;
   int row = 0;                          /* Row index               */&lt;br /&gt;
   int col = 0;                          /* Column index            */&lt;br /&gt;
   int best_row = 0;                     /* Best row index          */&lt;br /&gt;
   int best_col = 0;                     /* Best column index       */&lt;br /&gt;
   int i = 0;                            /* Loop index              */&lt;br /&gt;
   int j = 0;                            /* Loop index              */&lt;br /&gt;
   int new_score = 0;                    /* Score for current move  */&lt;br /&gt;
   int score = 100;                      /* Minimum opponent score  */&lt;br /&gt;
   char temp_board[SIZE][SIZE];          /* Local copy of board     */&lt;br /&gt;
   int temp_moves[SIZE][SIZE];           /* Local valid moves array */&lt;br /&gt;
   char opponent = (player == &amp;quot;O&amp;quot;)? &amp;quot;@&amp;quot; : &amp;quot;O&amp;quot;; /* Identify opponent */&lt;br /&gt;
   /* Go through all valid moves */&lt;br /&gt;
   for(row = 0; row &amp;lt; SIZE; row++)&lt;br /&gt;
     for(col = 0; col &amp;lt; SIZE; col++)&lt;br /&gt;
     {&lt;br /&gt;
       if(moves[row][col] == 0)&lt;br /&gt;
         continue;&lt;br /&gt;
 &lt;br /&gt;
       /* First make copies of the board and moves arrays */&lt;br /&gt;
       for(i = 0; i &amp;lt; SIZE; i++)&lt;br /&gt;
         for(j = 0; j &amp;lt; SIZE; j++)&lt;br /&gt;
           temp_board[i][j] = board[i][j];&lt;br /&gt;
   &lt;br /&gt;
       /* Now make this move on the temporary board */&lt;br /&gt;
       make_move(temp_board, row, col, player); &lt;br /&gt;
       /* find valid moves for the opponent after this move */&lt;br /&gt;
       valid_moves(temp_board, temp_moves, opponent);&lt;br /&gt;
       /* Now find the score for the opponents best move */&lt;br /&gt;
       new_score = best_move(temp_board, temp_moves, opponent);&lt;br /&gt;
       if(new_score&amp;lt;score)    /* Is it worse?           */&lt;br /&gt;
       {                      /* Yes, so save this move */&lt;br /&gt;
         score = new_score;   /* Record new lowest opponent score */&lt;br /&gt;
         best_row = row;  /* Record best move row             */&lt;br /&gt;
         best_col = col;  /* and column                       */&lt;br /&gt;
       }&lt;br /&gt;
     }&lt;br /&gt;
   /* Make the best move */&lt;br /&gt;
   make_move(board, best_row, best_col, player); &lt;br /&gt;
}&lt;br /&gt;
/************&lt;br /&gt;
 * Calculates the score for the current board position for the     *&lt;br /&gt;
 * player. player counters score +1, opponent counters score -1    *&lt;br /&gt;
 * First parameter is the board array                              *&lt;br /&gt;
 * Second parameter identifies the player                          *&lt;br /&gt;
 * Return value is the score.                                      *&lt;br /&gt;
 ************/&lt;br /&gt;
int get_score(char board[][SIZE], char player)&lt;br /&gt;
{&lt;br /&gt;
   int score = 0;      /* Score for current position */&lt;br /&gt;
   int row = 0;        /* Row index                  */    &lt;br /&gt;
   int col = 0;        /* Column index               */&lt;br /&gt;
   char opponent = player == &amp;quot;O&amp;quot; ? &amp;quot;@&amp;quot; : &amp;quot;O&amp;quot;;  /* Identify opponent */&lt;br /&gt;
   /* Check all board squares */&lt;br /&gt;
   for(row = 0; row &amp;lt; SIZE; row++)&lt;br /&gt;
     for(col = 0; col &amp;lt; SIZE; col++)&lt;br /&gt;
   { &lt;br /&gt;
     score -= board[row][col] == opponent; /* Decrement for opponent */&lt;br /&gt;
     score += board[row][col] == player;   /* Increment for player   */&lt;br /&gt;
   }&lt;br /&gt;
   return score;     &lt;br /&gt;
}&lt;br /&gt;
/************&lt;br /&gt;
 * Calculates the score for the best move out of the valid moves   *&lt;br /&gt;
 * for player in the current position.                             *&lt;br /&gt;
 * First parameter is the board array                              *&lt;br /&gt;
 * Second parameter is the moves array defining valid moves.       *&lt;br /&gt;
 * Third parameter identifies the player                           *&lt;br /&gt;
 * The score for the best move is returned                         *&lt;br /&gt;
 ************/&lt;br /&gt;
int best_move(char board[][SIZE], int moves[][SIZE], char player)&lt;br /&gt;
{&lt;br /&gt;
   int row = 0;     /* Row index    */&lt;br /&gt;
   int col = 0;     /* Column index */&lt;br /&gt;
   int i = 0;       /* Loop index   */&lt;br /&gt;
   int j = 0;       /* Loop index   */&lt;br /&gt;
   char opponent = player==&amp;quot;O&amp;quot;?&amp;quot;@&amp;quot;:&amp;quot;O&amp;quot;; /* Identify opponent */&lt;br /&gt;
   char new_board[SIZE][SIZE] = { 0 };  /* Local copy of board    */&lt;br /&gt;
   int score = 0;                       /* Best score             */&lt;br /&gt;
   int new_score = 0;                   /* Score for current move */&lt;br /&gt;
   /* Check all valid moves to find the best */&lt;br /&gt;
   for(row = 0 ; row&amp;lt;SIZE ; row++)&lt;br /&gt;
     for(col = 0 ; col&amp;lt;SIZE ; col++)&lt;br /&gt;
     {&lt;br /&gt;
       if(!moves[row][col])             /* Not a valid move?      */&lt;br /&gt;
         continue;                      /* Go to the next         */&lt;br /&gt;
 &lt;br /&gt;
       /* Copy the board */&lt;br /&gt;
       for(i = 0 ; i&amp;lt;SIZE ; i++)&lt;br /&gt;
         for(j = 0 ; j&amp;lt;SIZE ; j++)&lt;br /&gt;
           new_board[i][j] = board[i][j];&lt;br /&gt;
       /* Make move on the board copy */&lt;br /&gt;
       make_move(new_board, row, col, player);  &lt;br /&gt;
       /* Get score for move */&lt;br /&gt;
       new_score = get_score(new_board, player);  &lt;br /&gt;
       if(score&amp;lt;new_score)         /* Is it better?               */&lt;br /&gt;
               score = new_score;  /* Yes, save it as best score  */&lt;br /&gt;
     }&lt;br /&gt;
   return score;                   /* Return best score           */&lt;br /&gt;
}&lt;br /&gt;
/*************&lt;br /&gt;
 * Makes a move. This places the counter on a square,and reverses   *&lt;br /&gt;
 * all the opponent&amp;quot;s counters affected by the move.                *&lt;br /&gt;
 * First parameter is the board array.                              *&lt;br /&gt;
 * Second and third parameters are the row and column indices.      *&lt;br /&gt;
 * Fourth parameter identifies the player.                          *&lt;br /&gt;
 *************/&lt;br /&gt;
void make_move(char board[][SIZE], int row, int col, char player)&lt;br /&gt;
{&lt;br /&gt;
   int rowdelta = 0;                   /* Row increment              */&lt;br /&gt;
   int coldelta = 0;                   /* Column increment           */&lt;br /&gt;
   int x = 0;                          /* Row index for searching    */&lt;br /&gt;
   int y = 0;                          /* Column index for searching */&lt;br /&gt;
   char opponent = (player == &amp;quot;O&amp;quot;)? &amp;quot;@&amp;quot; : &amp;quot;O&amp;quot;;  /* Identify opponent */&lt;br /&gt;
   board[row][col] = player;           /* Place the player counter   */&lt;br /&gt;
   /* Check all the squares around this square */&lt;br /&gt;
   /* for the opponents counter                */&lt;br /&gt;
   for(rowdelta = -1; rowdelta &amp;lt;= 1; rowdelta++)&lt;br /&gt;
     for(coldelta = -1; coldelta &amp;lt;= 1; coldelta++)&lt;br /&gt;
     { &lt;br /&gt;
       /* Don&amp;quot;t check off the board, or the current square */&lt;br /&gt;
       if(row + rowdelta &amp;lt; 0 || row + rowdelta &amp;gt;= SIZE ||&lt;br /&gt;
          col + coldelta &amp;lt; 0 || col + coldelta &amp;gt;= SIZE || &lt;br /&gt;
                               (rowdelta==0 &amp;amp;&amp;amp; coldelta== 0))&lt;br /&gt;
         continue;&lt;br /&gt;
       /* Now check the square */&lt;br /&gt;
       if(board[row + rowdelta][col + coldelta] == opponent)&lt;br /&gt;
       {&lt;br /&gt;
         /* If we find the opponent, search in the same direction */&lt;br /&gt;
         /* for a player counter                                  */&lt;br /&gt;
         x = row + rowdelta;        /* Move to opponent */&lt;br /&gt;
         y = col + coldelta;        /* square           */&lt;br /&gt;
         for(;;)&lt;br /&gt;
         {&lt;br /&gt;
           x += rowdelta;           /* Move to the      */&lt;br /&gt;
           y += coldelta;           /* next square      */ &lt;br /&gt;
           /* If we are off the board give up */&lt;br /&gt;
           if(x &amp;lt; 0 || x &amp;gt;= SIZE || y &amp;lt; 0 || y &amp;gt;= SIZE)&lt;br /&gt;
             break;&lt;br /&gt;
 &lt;br /&gt;
           /* If the square is blank give up */&lt;br /&gt;
           if(board[x][y] == &amp;quot; &amp;quot;)&lt;br /&gt;
             break;&lt;br /&gt;
           /* If we find the player counter, go backwards from here */&lt;br /&gt;
           /* changing all the opponents counters to player         */&lt;br /&gt;
           if(board[x][y] == player)&lt;br /&gt;
           {&lt;br /&gt;
             while(board[x-=rowdelta][y-=coldelta]==opponent) /* Opponent? */&lt;br /&gt;
               board[x][y] = player;    /* Yes, change it */&lt;br /&gt;
             break;                     /* We are done    */&lt;br /&gt;
           } &lt;br /&gt;
         }&lt;br /&gt;
       }&lt;br /&gt;
     }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Storing and displaying proverbs in order of length==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
Beginning C, Third Edition&lt;br /&gt;
 By Ivor Horton&lt;br /&gt;
 ISBN: 1-59059-253-0&lt;br /&gt;
 Published: Apr 2004&lt;br /&gt;
 Publisher: apress&lt;br /&gt;
*/&lt;br /&gt;
/********************&lt;br /&gt;
 * This program will read any number of proverbs of any length.            *&lt;br /&gt;
 * The input buffer has a default size that is increased automatically     *&lt;br /&gt;
 * if it is not large enough. The current contents of the old buffer       *&lt;br /&gt;
 * are copied to the new and the old buffer is released before input       *&lt;br /&gt;
 * continues.                                                              *&lt;br /&gt;
 * The same applies to the number of proverbs. If the initial capacity     *&lt;br /&gt;
 * for pointers to proverbs is exceeded, a larger space is allocated       *&lt;br /&gt;
 * and the existing pointers are copied to the new memory before releasing *&lt;br /&gt;
 * the old memory.                                                         *&lt;br /&gt;
 * You could add printf() statements to record when new memory is allocated*&lt;br /&gt;
 * Values for BUFFER_LEN, BUFFER_LEN_INCR, and CAPACITY_INCR are set low   *&lt;br /&gt;
 * so as to cause frequent reallocation of memory for you to track.        *&lt;br /&gt;
 * In a practical program they would be set much higher to avoid           *&lt;br /&gt;
 * frequent allocation and release of memory.                              *&lt;br /&gt;
*********************/&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#define BUFFER_LEN 5          /* Initial length of input buffer     */&lt;br /&gt;
#define BUFFER_LEN_INCR 2     /* Increment to buffer length         */&lt;br /&gt;
#define CAPACITY_INCR 2       /* Increment to capacity for proverbs */&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
   char **pProverbs = NULL;        /* Pointer to string pointer           */&lt;br /&gt;
   char **temp = NULL;             /* Temporary pointer to string pointer */&lt;br /&gt;
   int capacity = 0;               /* Number of proverbs that can be stored */&lt;br /&gt;
   int count = 0;                  /* Number of proverbs read               */&lt;br /&gt;
   char *pbuffer = NULL;           /* Pointer to buffer        */&lt;br /&gt;
   char *pstart = NULL;            /* Pointer to buffer start  */&lt;br /&gt;
   char *pstr = NULL;              /* Pointer to a string      */&lt;br /&gt;
   int buffer_length = BUFFER_LEN; /* Buffer length            */&lt;br /&gt;
   int i = 0;                      /* Loop counter             */&lt;br /&gt;
   int j = 0;                      /* Loop counter             */&lt;br /&gt;
   pbuffer = (char*)malloc(BUFFER_LEN);  /* Initial buffer size   */&lt;br /&gt;
   pstart = pbuffer;                     /* Store start of buffer */&lt;br /&gt;
   for(;;)&lt;br /&gt;
   {&lt;br /&gt;
     if(count==capacity)&lt;br /&gt;
     {&lt;br /&gt;
       capacity += CAPACITY_INCR;&lt;br /&gt;
       temp = (char**)malloc(capacity*sizeof(char*));&lt;br /&gt;
       if(temp == NULL)       /* If memory was not allocated */&lt;br /&gt;
       {                      /* Output a message  and end   */&lt;br /&gt;
         printf(&amp;quot;Memory allocation failed. Terminating program.&amp;quot;);&lt;br /&gt;
         exit(1);&lt;br /&gt;
       }&lt;br /&gt;
     &lt;br /&gt;
       if(pProverbs == NULL)  /* Are there any proverbs?                 */&lt;br /&gt;
         pProverbs = temp;    /* No - so just copy address of new memory */&lt;br /&gt;
       else                   /* Yes - so copy data from old to new      */&lt;br /&gt;
       {&lt;br /&gt;
         for(i = 0 ; i&amp;lt;count ; i++)&lt;br /&gt;
           *(temp+i) = *(pProverbs+i);&lt;br /&gt;
         free(pProverbs);     /* Free the old memory */&lt;br /&gt;
         pProverbs = temp;    /* Copy address of new */&lt;br /&gt;
       } &lt;br /&gt;
       temp = NULL;           /* Reset pointer       */&lt;br /&gt;
     }&lt;br /&gt;
      printf(&amp;quot;Enter a proverb or press Enter to end:\n&amp;quot;);&lt;br /&gt;
     /* Read a proverb */&lt;br /&gt;
     while((*pbuffer++ = getchar()) != &amp;quot;\n&amp;quot;)&lt;br /&gt;
     {&lt;br /&gt;
       if(pbuffer-pstart == buffer_length)     /* Check for buffer full  */&lt;br /&gt;
       {&lt;br /&gt;
         buffer_length += BUFFER_LEN_INCR;     /* Increase buffer length */&lt;br /&gt;
         pstr = (char*)malloc(buffer_length);  /* Allocate new buffer    */&lt;br /&gt;
         /* Copy old buffer contents to new */&lt;br /&gt;
         for(i = 0; i&amp;lt;pbuffer-pstart ; i++)&lt;br /&gt;
           *(pstr+i) = *(pstart+i);&lt;br /&gt;
         pbuffer = pstr+(pbuffer-pstart);      /* Address of next position in new */&lt;br /&gt;
         free(pstart);                         /* Release old buffer memory       */&lt;br /&gt;
         pstart = pstr;                        /* Set to start of new buffer      */&lt;br /&gt;
         pstr = NULL;                          /* Reset pointer                   */&lt;br /&gt;
       }&lt;br /&gt;
     }&lt;br /&gt;
     /* check for empty line indicating end of input */&lt;br /&gt;
     if((pbuffer-pstart)&amp;lt;2)&lt;br /&gt;
       break;&lt;br /&gt;
     /* Check for string too long */&lt;br /&gt;
     if((pbuffer - pstart) == BUFFER_LEN &amp;amp;&amp;amp; *(pbuffer-1)!= &amp;quot;\n&amp;quot;)&lt;br /&gt;
     {&lt;br /&gt;
       printf(&amp;quot;String too long ?maximum %d characters allowed.&amp;quot;, &lt;br /&gt;
                                                       BUFFER_LEN);&lt;br /&gt;
       pbuffer = pstart;&lt;br /&gt;
       continue;&lt;br /&gt;
     }&lt;br /&gt;
     *(pbuffer-1) = &amp;quot;\0&amp;quot;;                  /* Add string terminator */&lt;br /&gt;
     pbuffer = pstart;&lt;br /&gt;
     *(pProverbs+count) = (char*)malloc(strlen(pstart)+1);&lt;br /&gt;
     strcpy(*(pProverbs+count++),pstart);&lt;br /&gt;
   }&lt;br /&gt;
   /* Order the proverbs from shortest to longest */&lt;br /&gt;
  for(i = 0 ; i&amp;lt;count-1 ; i++)&lt;br /&gt;
    for(j = i+1 ; j&amp;lt;count ; j++)&lt;br /&gt;
      if(strlen(*(pProverbs+i))&amp;gt;strlen(*(pProverbs+j)))&lt;br /&gt;
      {&lt;br /&gt;
        pstr = *(pProverbs+i);&lt;br /&gt;
        *(pProverbs+i) = *(pProverbs+j);&lt;br /&gt;
        *(pProverbs+j) = pstr;&lt;br /&gt;
      }&lt;br /&gt;
   /* Output all the strings */&lt;br /&gt;
   printf(&amp;quot;\nIn ascending length order, the proverbs you entered are:\n&amp;quot;);&lt;br /&gt;
   for (i = 0 ; i&amp;lt;count ; i++ )&lt;br /&gt;
   {&lt;br /&gt;
      printf(&amp;quot;\n%s&amp;quot;, *(pProverbs + i));&lt;br /&gt;
      free(*(pProverbs + i));   /* Release the memory for the proverb  */&lt;br /&gt;
      *(pProverbs + i) = NULL;  /* Set pointer back to NULL for safety */&lt;br /&gt;
   }&lt;br /&gt;
   free(pProverbs);             /* Release memory for the pointers     */&lt;br /&gt;
   free(pstart);                /* Release memory for the buffer       */&lt;br /&gt;
}&lt;br /&gt;
 &lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==String length and string compare==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
  char str1[80], str2[80];&lt;br /&gt;
  int i;&lt;br /&gt;
  printf(&amp;quot;Enter the first string: &amp;quot;);&lt;br /&gt;
  gets(str1);&lt;br /&gt;
  &lt;br /&gt;
  printf(&amp;quot;Enter the second string: &amp;quot;);&lt;br /&gt;
  gets(str2);&lt;br /&gt;
  /* see how long the strings are */&lt;br /&gt;
  printf(&amp;quot;%s is %d chars long\n&amp;quot;, str1, strlen(str1));&lt;br /&gt;
  printf(&amp;quot;%s is %d chars long\n&amp;quot;, str2, strlen(str2));&lt;br /&gt;
  /* compare the strings */&lt;br /&gt;
  i = strcmp(str1, str2);&lt;br /&gt;
  if(!i) &lt;br /&gt;
      printf(&amp;quot;The strings are equal.\n&amp;quot;);&lt;br /&gt;
  else if(i&amp;lt;0) &lt;br /&gt;
      printf(&amp;quot;%s is less than %s\n&amp;quot;, str1, str2);&lt;br /&gt;
  else &lt;br /&gt;
      printf(&amp;quot;%s is greater than %s\n&amp;quot;, str1, str2);&lt;br /&gt;
  /* concatenate str2 to end of str1 if&lt;br /&gt;
     there is enough room */&lt;br /&gt;
  if(strlen(str1) + strlen(str2) &amp;lt; 80) {&lt;br /&gt;
       strcat(str1, str2);&lt;br /&gt;
       printf(&amp;quot;%s\n&amp;quot;, str1);&lt;br /&gt;
  }&lt;br /&gt;
  /* copy str2 to str1 */&lt;br /&gt;
  strcpy(str1, str2);&lt;br /&gt;
  printf(&amp;quot;%s %s\n&amp;quot;, str1, str2);&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Use gets to get the whole string==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
  char str[80];&lt;br /&gt;
  printf(&amp;quot;Enter a string (less than 80 chars): &amp;quot;);&lt;br /&gt;
  &lt;br /&gt;
  gets(str);&lt;br /&gt;
  &lt;br /&gt;
  printf(str); /* output the string */&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>