There are two errors that show up: main.c:80: warning: ‘main’ is normally a non-static function main.c:88: error: expected declaration or statement at end of input and I cant't seem to find the problem... There number of curly braces is equal... What seems to be the problem?
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <getopt.h>
#include <string.h>
#include "main-getopt.h"
void print_usage_and_abort( const char *message )
{
if( NULL != message )
fprintf( stderr, "Error: %s\n", message );
fprintf( stderr, "Usage: partitioner -n <nodes> [ -f <basename> ]\n\n" );
exit( -1 );
}
void parsing (int argc, char **argv, struct Params *params)
{
char error_message[256];
params->nodes = 0;
memcpy( params->filename_base, "output", strlen("output") + 1 );
int opt;
size_t len;
int numarg;
while ((opt = getopt(argc, argv, "n:f:")) != -1) {
int i;
for (i = 1; i < argc; i++)
{
if (argv[i][0] == '-')
{
if (i+1 == argc || argv[i+1][0] == '-')
{
sprintf( error_message, "No Filename");
print_usage_and_abort( error_message );
}
if (argv[i][1] == 'n')
{
numarg = atoi( optarg );
if( numarg < 1 || numarg > 2048 )
{
sprintf( error_message, "Number of nodes agrument expects a "
"number between 1 and 2048, actual %s", optarg );
print_usage_and_abort( error_message );
}
}
else if (argv[i][1] == 'f')
len = strlen( optarg );
// limit to buffer capacity
if( len >= MAX_FILENAME_BASE )
{
sprintf( error_message, "Base filename parameter length is "
"expected to be less than %d but is %d",
(int)MAX_FILENAME_BASE, (int)len );
print_usage_and_abort( error_message );
}
else if(len<MAX_FILENAME_BASE)
{
memcpy( params->filename_base, optarg, len + 1 );
break;
}
else
{
sprintf( error_message, "Unknown command switch %c", (char)optopt );
print_usage_and_abort( error_message );
break;
}
}
}
if( 0==params->nodes )
{
sprintf( error_message, "Number of nodes switch -n is required" );
print_usage_and_abort( error_message );
}
}
int main(int argc, char *argv[])
{
struct Params params;
parse_arguments( argc, argv, ¶ms );
fprintf( stdout, "Parameters are:\n\tNumber of nodes:\t%d\n\t"
"Filename base:\t%s\n\n", params.nodes, params.filename_base );
return 0;
}
I've edited indentation for you. Do you see now that somewhere in
parsing
function you've missed one closing bracket?