I need to scan a crossword king of thing like this:

a b c o d e f g h i
j k l m l n o p q r
s t r z a l q w s x
c d e r f v e b g t
y h y u j m k h i l
o p p l o i k m j z
x c v b n m a s f g
h j k l q w r t y u
o p q z z b n h y t
r e k l j g h r s a

Into a 2D char array, I have trouble doing this with gets() which I know doesn't work, as well trouble with scanf().
Any suggestions?

One way:

#include <stdio.h>

int main()
{
   const char filename[] = "file.txt";
   FILE *file = fopen(filename, "r");
   if ( file )
   {
      char crossword[10][10];
      int i, j;
      for ( i = 0; i < sizeof crossword / sizeof *crossword; ++i )
      {
         for ( j = 0; j < sizeof *crossword / sizeof **crossword; ++j )
         {
            if ( fscanf(file, "%c ", &crossword[i][j]) != 1 )
            {
               puts("error reading file");
               return 0;
            }
         }
      }
      fclose(file);
      for ( i = 0; i < sizeof crossword / sizeof *crossword; ++i )
      {
         for ( j = 0; j < sizeof *crossword / sizeof **crossword; ++j )
         {
            printf("%c ", crossword[i][j]);
         }
         putchar('\n');
      }
   }
   else
   {
      perror(filename);
   }
   return 0;
}

/* file.txt/my output
a b c o d e f g h i
j k l m l n o p q r
s t r z a l q w s x
c d e r f v e b g t
y h y u j m k h i l
o p p l o i k m j z
x c v b n m a s f g
h j k l q w r t y u
o p q z z b n h y t
r e k l j g h r s a
*/
This article has been dead for over six months. Start a new discussion instead.