/*
 * Convert a string to an integer.
 */

#include <iostream>
#include <stdlib.h>
#include <stdio.h>

using namespace std;

%%{
	machine atoi;
	write data noerror;
}%%

int atoi( char *str )
{
	char *p = str;
	int cs, val = 0;
	bool neg = false;

	%%{
		action see_neg {
			neg = true;
		}

		action add_digit { 
			val = val * 10 + (fc - '0');
		}

		main := 
			( '-'@see_neg | '+' )? ( digit @add_digit )+ 
			'\n' @{ fbreak; };

		# Initialize and execute.
		write init;
		write exec noend;
	}%%

	if ( neg )
		val = -1 * val;

	if ( cs < atoi_first_final )
		cerr << "atoi: there was an error" << endl;

	return val;
};


#define BUFSIZE 1024

int main()
{
	char buf[BUFSIZE];
	while ( fgets( buf, sizeof(buf), stdin ) != 0 ) {
		int value = atoi( buf );
		cout << value << endl;
	}
	return 0;
}


Remove the 'noend' write option. This example is referenced a lot and as a first example it shouldn't contain a special purpose write option like 'noend'.
/*
 * Convert a string to an integer.
 */

#include <stdlib.h>
#include <string.h>
#include <stdio.h>

%%{
	machine atoi;
	write data;
}%%

long long atoi( char *str )
{
	char *p = str, *pe = str + strlen( str );
	int cs;
	long long val = 0;
	bool neg = false;

	%%{
		action see_neg {
			neg = true;
		}

		action add_digit { 
			val = val * 10 + (fc - '0');
		}

		main := 
			( '-'@see_neg | '+' )? ( digit @add_digit )+ 
			'\n';

		# Initialize and execute.
		write init;
		write exec;
	}%%

	if ( neg )
		val = -1 * val;

	if ( cs < atoi_first_final )
		fprintf( stderr, "atoi: there was an error\n" );

	return val;
};


#define BUFSIZE 1024

int main()
{
	char buf[BUFSIZE];
	while ( fgets( buf, sizeof(buf), stdin ) != 0 ) {
		long long value = atoi( buf );
		printf( "%lld\n", value );
	}
	return 0;
}