All pastes #217879 Raw Edit

Wolever

public c v1 · immutable
#217879 ·published 2006-10-23 21:32 UTC
rendered paste body
#include <string.h>#include <stdio.h>#include <unistd.h>static int offsets[] = { -15 - 1, -15, -15+1, -1, 1, 15 - 1, 15, 15+1 };char board[15*15], word[32];#define NFS (offset?offsets[direction]:0)int find_word(int x, int offset, int direction){  if ((NFS + x >= 0) && (tolower(board[NFS + x]) == tolower(word[offset])))      if (((strlen(word)-1 == offset) || find_word(NFS + x, offset+1, direction)) && (board[NFS + x] = toupper(board[NFS + x])))        return 1;  return 0;}void print_board(){  int x=0;  while (x < 15*15)    printf("%c%s", board[x++], !(x%15)?"\n":"");}int main(){  int c, x, wc;  FILE *inf;  inf = fopen("data","r");  while((c=fgetc(inf)) != EOF)    if (isalpha(c))      board[x++] = c;  print_board();  printf("Please enter a word: ");  while (scanf("%s", word) != EOF){    for (c=wc=0; c < 15*15*8; ++c)      if (find_word(c/8,0,c%8)) ++wc;    printf("%s was found %d times\n", word, wc);    print_board();    printf("Please enter a word: ");  }  return 0;}