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>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

#define ll (long long)
#define REP(i,n) for(int i = 0;i<(int)n;i++)
#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (a);i>(b);i--)
#define COUNTER int i= 0,j = 0,k = 0,l = 0,m = 0, n= 0;
#define RETURN cout << endl;
/*vector<vector<int>>ArrayName = vector<vector<int>>(sizeofx, vector<int>(sizeofy, 0));*/
using namespace std;



int dfs (int x,int y,vector<vector<char>>&v);

int lim_x,lim_y;
int mx[] = {-1,1,0,0};
int my[] = {0,0,-1,1,};

int main (void){
    
    int x,y;
    int sh_x = 0,sh_y = 0;
    
    while(cin >> lim_x >> lim_y,lim_x+lim_y)
        {
            vector<vector<char>>v = vector<vector<char>>(lim_y, vector<char>(lim_x, 0));
            REP(i,lim_y)
            REP(j,lim_x)
            {
                cin >> v[i][j];
                if(v[i][j] == '@')
                    {
                        sh_y = i;
                        sh_x = j;
                    }
            }
            //cout << lim_x << " " << lim_y << endl;
            //cout << sh_x  <<" "<< sh_y << endl;
            cout << dfs(sh_x,sh_y,v) << endl;
            /*v is array name(pointer)*/
      
        }
    return 0;
}

int dfs(int x,int y, vector<vector<char>>&v)
{
    int counter = 1;
    for(int i = 0; i<4;i++){
            int tx = x+mx[i],ty = y+my[i];
            if((tx >= 0 && tx<lim_x) && (ty >= 0 && ty <lim_y) && (v[ty][tx] == '.'))
            {
                v[ty][tx] = '#';
                //cout << v[ty][tx] << endl;
                counter += dfs(tx, ty, v);
                //cout << "come on !" << endl;
            }
                
        }
            
    return counter;
}

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

int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
int W, H;
string mem[20];
bool res[20][20];

int dfs(int sx, int sy)
{
  for(int i = 0; i < 20; i++)
    for(int j = 0; j < 20; j++)
      res[i][j] = 0;
  queue<int> q;
  q.push(sx);
  q.push(sy);
  while(!q.empty())
  {
    int x = q.front(); q.pop();
    int y = q.front(); q.pop();
    res[y][x] = true;
    for(int i = 0; i < 4; i++)
    {
      
      int tx = x + dx[i];
      int ty = y + dy[i];
      if(tx >= 0 && ty >= 0 && tx < W && ty < H && mem[ty][tx] == '.' && !res[ty][tx])
      {
        q.push(tx);
        q.push(ty);
      }
    }
  }
  int ans = 0;
  for(int y = 0; y < H; y++)
    for(int x = 0; x < W; x++)
      ans += res[y][x];
  return ans;
}

int main()
{
loop:
  for(int i = 0; i < 20; i++)
    mem[i] = "";
  int sx = -1, sy;
  cin >> W >> H;
  if(!(W || H))
    return 0;
  for(int i = 0; i < H; i++)
  {
    cin >> mem[i];
    if(sx != -1)
      continue;
    for(int j = 0; j < W; j++)
    {
      if(mem[i][j] == '@')
      {
        sx = j;
        sy = i;
        break;
      }
    }
  }
  cout << dfs(sx, sy) << endl;
  goto loop;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int w,h;
  int vx[4]={1,0,-1,0};
  int vy[4]={0,-1,0,1};
  while(cin>>w>>h,h+w){
    string str[h];
    for(int i=0;i<h;i++)cin>>str[i];
    bool Map[h][w];
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)
	Map[i][j]=false;
    queue<pair<int,int> >que;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(str[i][j]=='@'){
	  que.push(mp(i,j));
	  Map[i][j]=true;
	}
      }
    }
    while(!que.empty()){
      pair<int,int>now=que.front();
      que.pop();
      for(int i=0;i<4;i++){
	if(now.F+vy[i]>=0&&now.S+vy[i]<w&&now.F+vx[i]>=0&&now.F+vx[i]<h&&(!Map[now.F+vx[i]][now.S+vy[i]])&&str[now.F+vx[i]][now.S+vy[i]]=='.'){
	  Map[now.F+vx[i]][now.S+vy[i]]=true;
	  que.push(mp(now.F+vx[i],now.S+vy[i]));
	}
      }
    }
    ll ans=0;
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)
	if(Map[i][j])
	  ans++;
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
const int inf = 1001001001;


int w, h;
int a[20][20];
int sw, sh;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int D[20][20];
int Ans = 1;


int main()
{
    while(cin >> w, w != 0)
    {
        Ans = 1;
        cin >> h;
        
        for(int i = 0; i < 20; i++)
        {
            for(int j = 0; j < 20; j++)
            {
                D[i][j] = inf;
            }
        }
        
        for(int i = 0; i < h; i++)
        {
            for(int j = 0; j < w; j++)
            {
                char x;
                cin >> x;
                if(x == '.')
                {
                    a[j][i] = 1;
                }
                else if(x == '#')
                {
                    a[j][i] = 0;
                }
                else
                {
                    sw = j;
                    sh = i;
                    a[j][i] = 100;
                }
            }
        }
        queue< pair<int, int> > Q;
        pair<int, int> S;
        S = make_pair(sw, sh);
        Q.push(S);
        D[sw][sh] = 0;
        int k = 0;
        while(! Q.empty())
        {
            pair<int, int> cur = Q.front();
            Q.pop();
            int x = cur.first;
            int y = cur.second;
            for(int i = 0; i < 4; i++)
            {
                if(a[x+dx[i]][y+dy[i]] == 1 && 0 <= x+dx[i] && x+dx[i] < w && 0 <= y+dy[i] && y+dy[i] < h && D[x+dx[i]][y+dy[i]] == inf)
                {
                    D[x+dx[i]][y+dy[i]] = D[x][y] + 1;
                    Ans = Ans + 1;
                    pair<int, int> T;
                    T = make_pair(x+dx[i], y+dy[i]);
                    Q.push(T);
                }
            }
        }
        cout << Ans << endl;
    }
}