Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var (
	sc = bufio.NewScanner(os.Stdin)
)

type Color int

const (
	ColorBlack Color = iota
	ColorRed
)

type Node struct {
	ID    int
	X, Y  int
	Color Color
	Nexts []*Node
}

func main() {
	for sc.Scan() {
		if sc.Text() == "0 0" {
			break
		}
		chunks := strings.Split(sc.Text(), " ")
		w, _ := strconv.Atoi(chunks[0])
		h, _ := strconv.Atoi(chunks[1])

		// Initialize map
		m := map[int]map[int]*Node{}
		for x := 1; x <= w; x++ {
			m[x] = map[int]*Node{}
			for y := 1; y <= h; y++ {
				m[x][y] = &Node{ID: x + y*w, X: x, Y: y}
			}
		}
		for x := 1; x <= w; x++ {
			for y := 1; y <= h; y++ {
				nexts := []*Node{}
				if n, ok := m[x-1][y]; ok {
					nexts = append(nexts, n)
				}
				if n, ok := m[x][y-1]; ok {
					nexts = append(nexts, n)
				}
				if n, ok := m[x+1][y]; ok {
					nexts = append(nexts, n)
				}
				if n, ok := m[x][y+1]; ok {
					nexts = append(nexts, n)
				}
				m[x][y].Nexts = nexts
			}
		}

		// Set colors
		queue := []*Node{}
		touchedIDs := map[int]struct{}{}
		for y := 1; y <= h; y++ {
			sc.Scan()
			for i, c := range sc.Text() {
				switch c {
				case '.', '@':
					n := m[i+1][y]
					n.Color = ColorBlack
					if c == '@' {
						queue = append(queue, n)
						touchedIDs[n.ID] = struct{}{}
					}
				case '#':
					m[i+1][y].Color = ColorRed
				}
			}
		}

		// Search
		visitedIDs := map[int]struct{}{}
		for {
			if len(queue) == 0 {
				break
			}
			n := queue[0]
			queue = queue[1:]
			visitedIDs[n.ID] = struct{}{}
			for _, next := range n.Nexts {
				if next.Color == ColorRed {
					continue
				}
				if _, ok := touchedIDs[next.ID]; !ok {
					queue = append(queue, next)
					touchedIDs[n.ID] = struct{}{}
				}
			}
		}
		fmt.Println(len(visitedIDs))
	}
}

C++: #include<iostream>
using namespace std;
int W,H;
int t[20][20];
int c;
char ch;

int dy[4] = {0,1,0,-1};
int dx[4] = {1,0,-1,0};

bool inField(int y,int x){
  if( 0<=y && y<H && 0<=x && x<W ){
    return true;
  }else{
    return false;
  }
}

void visit(int y,int x){
  c++;
  t[y][x]=1;
  for(int i=0;i<4;i++){
    int ny=y+dy[i];
    int nx=x+dx[i];
    if( inField(ny,nx) && t[ny][nx]==0){
      visit(ny,nx);
    }
  }
}
int main(){
  while(1){
    cin>>W>>H;
    if(W==0&&H==0)break;
    int sy,sx;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        cin>>ch;
        if(ch=='.'){
          t[i][j]=0;
        }
        if(ch=='@'){
          sy=i;
          sx=j;
        }
        if(ch=='#'){
          t[i][j]=-1;
        }
      }
    }
    c=0;
    visit(sy,sx);
    cout<<c<<endl;
  }
  return 0; 
}

C++: #include<iostream>
using namespace std;

int dfs(int x,int y,int count);

int w,h;
int dx[4]={0,-1,0,1};
int dy[4]={-1,0,1,0};
int sum=0;
char maps[21][21];

int main(){
  int sx,sy;
  cin >> h >> w;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> maps[i][j];
      if(maps[i][j]=='@'){
	sy=i;
	sx=j;
      }
    }
  }
  int ans = dfs(sx,sy,0);
  cout << "¥" << ans << endl;
}

int dfs(int x,int y,int count){
  int nx,ny;
  for(int i=0;i<4;i++){
    nx=x+dx[i];
    ny=y+dy[i];
    maps[y][x]='#';
    if(0<=nx && nx<w && 0<=ny && ny<h && maps[ny][nx]!='#'){
      sum++;
      dfs(nx,ny,count+1);
    }
  }
  return sum;
}

C++: #include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  while (true) {
    int w, h; cin >> w >> h;
    if (w == 0) return;
    vstr a(h); rep(i, h) cin >> a[i];
    int sx, sy;
    rep(i, h) rep(j, w) if (a[i][j] == '@') sx = i, sy = j;
    int cnt = 0;
    function<void(int, int)> rec = [&](int x, int y) {
      cnt++;
      a[x][y] = '#';
      rep(i, 4) {
        int wx = x + (i - 1) % 2;
        int wy = y + (i - 2) % 2;
        if (wx < 0 || wx >= h || wy < 0 || wy >= w) continue;
        if (a[wx][wy] == '#') continue;
        rec(wx, wy);
      }
    };
    rec(sx, sy);
    cout << cnt << '\n';
  }
}

C++: #include <iostream>
using namespace std;
char f[22][22];
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0}; 
int w,h,sx,sy;
void dfs(int x,int y)
{
	if(f[x][y]!='.')return;
	f[x][y]='7';
	for(int i=0;i<4;i++)
	{
		int nx = x + dx[i];
		int ny = y + dy[i];
		if(nx<0||nx>=h||ny<0||ny>=w)continue;
		if(f[nx][ny]!='.')continue;
		dfs(nx,ny);
	}
	return;
}
int main()
{
	while(1)
	{
		cin >> w >> h;
		if(w==0&&h==0)break;
		for(int i=0;i<h;i++)
		{
			for(int j=0;j<w;j++)
			{
				cin >> f[i][j];
				if(f[i][j]=='@')
				{
					sx = i;
					sy = j;
					f[i][j]='.';
				}
			}
		}
		dfs(sx,sy);
		int ans = 0;
		for(int i=0;i<h;i++)
		{
			for(int j=0;j<w;j++)
			{
				if(f[i][j]=='7')ans++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}