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 <stdio.h>
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <complex>
#include <vector>
#include <tuple>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <time.h>
#define all(c) ((c).begin(),(c).end())
#define rall(c) (c).rbegin(),(c).rend()
#define sort(v,n) sort(v,v+n)
#define vsort(v) sort(v.begin(),v.end())
#define vvsort(v) sort(v.begin(),v.end(),greater<int>())
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int w, h;
char a[21][21];

int bfs(int sh,int sw) {
	//cout<<"--------------------------------------------"<<endl;
	int ans = 1;
	queue<pair<int,int> > q;
	q.push(pair<int,int>(sh, sw));
	while (!q.empty())
	{
		//for (int i = 0; i < h; i++) {
			//for (int j = 0; j < w; j++) {
				//cout << a[i][j] << " ";
			//}
			//cout << endl;
		//}

		//cout << ans << endl;
		int nowx, nowy;
		nowy = q.front().first;
		nowx = q.front().second;
		//cout << nowy << " " << nowx << endl;
		q.pop();
		if (a[nowy][nowx + 1] == '.' && nowx<w-1) {
			q.push(pair<int,int>(nowy, nowx + 1));
			a[nowy][nowx + 1] = '#';
			ans++;
		}
		if (a[nowy][nowx - 1]=='.' && nowx>0) {
			q.push(pair<int,int>(nowy, nowx - 1));
			a[nowy][nowx - 1] = '#';
			ans++;
		}
		if (a[nowy + 1][nowx] == '.' && nowy<h-1) {
			q.push(pair<int,int>(nowy + 1, nowx));
			a[nowy + 1][nowx] = '#';
			ans++;
		}
		if (a[nowy - 1][nowx] == '.' && nowy>0) {
			q.push(pair<int,int>(nowy - 1, nowx));
			a[nowy - 1][nowx] = '#';
			ans++;
		}
	}
	return ans;
}

int main() {
	while (cin >> w >> h, w) {
		int sw, sh;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cin >> a[i][j];
				if (a[i][j] == '@') {
					sw = j;
					sh = i;
				}
			}
		}
		cout << bfs(sh, sw) << endl;
	}
}

C++: #include <iostream>

char table[100][100];
using namespace std;


int f(int w, int h, int x, int y){
  int ret = 0;
  if(x < 0 || y < 0 || x >= w || y >= h){
    return 0;
  }
  if(table[y][x] == '#'){
    return 0;
  }
  ret = 1;
  table[y][x] = '#';
  ret += f(w, h, x, y + 1);
  ret += f(w, h, x, y - 1);
  ret += f(w, h, x - 1, y);
  ret += f(w, h, x + 1, y);
  return ret;
}

int main(){
  while(true){
    int startX, startY;
    int width, height;
    cin >> width >> height;
    if(width == 0 && height == 0){
      break;
    }
    for(int i = 0; i < height; i++){
      for(int j = 0; j < width; j++){
        cin >> table[i][j];
        if(table[i][j] == '@'){
          //cout << "startX = " << j << " startY = " << i << endl;
          startX = j;
          startY = i;
          table[i][j] = '.';
        }
      }
      
    }
    cout << f(width, height, startX, startY) << endl;
  }
}

C++: #include<bits/stdc++.h>
char n[100][100];int k[100][100],l[100][100],sum,H,W,i,j,m,s;
#define A(B,C) if(k[B][C]!=1){l[B][C]=1;}
int main(){while(true){s=0;memset(l,0,sizeof(l));std::cin>>W>>H;if(W==0){break;}for(i=1;i<=H;i++){for(j=1;j<=W;j++){std::cin>>n[i][j];if(n[i][j]=='.'){k[i][j]=0;}else if(n[i][j]=='@'){k[i][j]=2;l[i][j]=1;}else{k[i][j]=1;}}}
for(i=0;i<2500;i++){for(j=1;j<=H;j++){for(m=1;m<=W;m++){if(l[j][m]==1){A(j-1,m);A(j+1,m);A(j,m-1);A(j,m+1);}}}}
for(j=1;j<=H;j++){for(m=1;m<=W;m++){if(l[j][m]==1){s++;}}}scanf("%d\n",s);}}

C++: #include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct DataSet{
    int x, y;
    int ax, ay;
    string str;
};

int search(int xSize, int ySize, int x, int y, string& s){
    //cout << '[' << x << ',' << y << ']' << endl;
    int ret = 0;
    int nowPos = x + y * xSize;
    s[nowPos] = '#';
    ++ret;
    
    if(s[nowPos - 1] == '.' && x != 0){
        ret += search(xSize, ySize, x-1, y, s);
    }
    if(s[nowPos + 1] == '.' && x + 1 != xSize){
        ret += search(xSize, ySize, x+1, y, s);
    }
    if(s[nowPos - xSize] == '.' && y != 0){
        ret += search(xSize, ySize,x, y-1, s);
    }
    if(s[nowPos + xSize] == '.' && y + 1 != ySize){
        ret += search(xSize, ySize, x, y+1, s);
    }
    return ret;
}

int main()
{
    vector<DataSet> dataSets;
    char word;
    
    while(cin){
        DataSet dataSet;
        cin >> dataSet.x >> dataSet.y;
        for(int i = 0; i < dataSet.y * dataSet.x; i++){
            cin >> word;
            if(word == '@'){
                dataSet.ax = i % dataSet.x;
                dataSet.ay = i / dataSet.x;
            }
            //cout << line << endl;
            dataSet.str += word;
        }
        dataSets.push_back(dataSet);
    }
    dataSets.pop_back();
    
    //cout << dataSets.back().x << ' ' << dataSets.back().y << endl;
    //cout << dataSets.back().ax << ' ' << dataSets.back().ay << endl;
    //cout << dataSets.back().str;
    
    for(auto dataSet : dataSets){
        if(dataSet.x == 0) continue;
        cout << search(dataSet.x, dataSet.y, dataSet.ax, dataSet.ay, dataSet.str) << endl;
    }
    
    return 0;
}