Err: a function-definition is not allowed here before '{' token [SOLVED]

I've created an EEPROM mission file writer for a GPS RC car I'm working on and the waypoints (14 bytes long - 1 for index, 1 for stage, 4 for lat, 4 for lon, 4 for alt) are stored in the EEPROM and retrieved incrementally in the guidance code. I use the same routine in my guidance code and it functions fine but when converting the mission.h file (or rather the array of the mission) it is throwing up errors. I'm sure I've missed something stupid but for the life of me cannot see it, help a frustrated buffoon.

Errors

WaypointWriter.cpp: In function 'void read_mission()':
WaypointWriter:60: error: a function-definition is not allowed here before '{' token
WaypointWriter:72: error: expected `}' at end of input

WaypointWriter.pde

#include "WConstants.h"
#include <WProgram.h>
#include <inttypes.h>
#include <math.h>
#include <avr/eeprom.h>

// INCLUDE YOUR MISSION FILE - CHANGE THE NAME TO YOUR FILE
#include "mission_example.h"

#define EEPROM_MAX_ADDR = 36;

struct Location {
  uint8_t  id;
  uint8_t  stg;
  int32_t  lat;
  int32_t  lon;
  int32_t  alt;
};
struct Location WP		= {0,0,0,0,0};

const float t7			= 10000000.0;
uint8_t waypoint_total;
boolean success = false;
byte j;

void setup()
{
	waypoint_total = (sizeof(mission) / 14);
	eeprom_write_byte((uint8_t*)12,waypoint_total);
	eeprom_write_byte((uint8_t*)13,WP_RADIUS);
	read_mission();
}

void loop()
{
}
void read_mission()
{
	struct Location loc;
	// Put mission array into Loccation structure
	for (byte i = 0; i < waypoint_total; i++){
		loc.id 		= (uint8_t) mission[i][0];
		loc.stg 	= (uint8_t) mission[i][1];
		loc.lat 	= (long)(mission[i][2] * t7);
		loc.lon 	= (long)(mission[i][3] * t7);
		loc.alt 	= (long)(mission[i][4]);
		// Write Location into EEPROM
		j = (i + 1);
		if (j < 36){
		write_WP(j, loc);
	}
}

void write_WP(uint8_t address, struct Location loc1)  // just until waypointer writer is done
{
  int addr;
  addr = (address * 14);
  eeprom_write_byte((uint8_t*)addr, loc1.id);
  addr++;
  eeprom_write_byte((uint8_t*)addr, loc1.stg);
  addr++;
  eeprom_write_dword((uint32_t*)addr, loc1.lat);
  addr += 4;
  eeprom_write_dword((uint32_t*)addr, loc1.lon);
  addr += 4;
  eeprom_write_dword((uint32_t*)addr, loc1.alt);
}

mission_example.h

#define WP_RADIUS 3 	// What is the minimum distance to reach a waypoint? in metres

float mission[][5] = {
	//id	stg	Latitude	Longitude	Altitude
	{0,	0,	51.183633,	21.26162,	100},
	{0,	0,	51.183338,	21.25623,	100},
	{0,	0,	51.183633,	21.26162,	100},
	{0,	0,	51.183466,	21.26418,	100},
};
if (j < 36){

They usually come in pairs

The editor in the Arduino environment highlights the matching open-brace when you type the closing brace - you might find this useful to know.

Also here we have the very common situation where one error leads to lots of spurious error messages too - there is an art to finding the real error amongst them, but mismatched braces are a common cause of this.

OMG I cannot believe i missed that what a smeghead. Thanks guys for not mercilessly ragging on me too :slight_smile:

I do wonder about the environment sometimes but no one suggests other options so I never leave it.

They usually come in pairs

This is why I never put the opening brace on the same line as the code it goes with. I like to see the braces lined up, and the code in between properly indented.

		if (j < 36){
		write_WP(j, loc);
	}

just seems harder to match the braces than

   if (j < 36)
   {
      write_WP(j, loc);
   }

The IDE also includes a formatting tool, under the Tools menu. It will help you line up the braces, if you put the open one on a new line, and will auto-indent the code between the braces.