I'm trying to take an input file like this:
Code:
+ LAST, FIRST M. | fmlast
: quiz | 50 
: program | 100
- fmlast | 29
- fmlast | -10 no block comments | -20 improper memory use
and parse it to output this to the screen
Code:
grade info for 'fmlast'

Assignment : quiz
points : 29 /  50

Assignment : program
 -10 no block comments 
 -20 improper memory use
points : 70 / 100

TOTAL : 99 / 150 = 66.00 percent
I would run this program with the command
Code:
./regex input.txt fmlast
in order to parse the input.txt file and pull out the assignment names and their worth, but then only the results for student named "fmlast" as there will be other students included in the file.

My problem now is that I'm getting a seg fault at the fclose() and I'm thinking the fopen() isn't working properly. After that I need to get into the while loop to look for this:

Assignment : quiz
points : 29 / 50

My current code is here
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <sys/types.h>
#include <regex.h>

#define BUF_SIZE 256

int main(int argc, char ** argv)
{

		char name[BUF_SIZE];
		char line[BUF_SIZE];
		char file[BUF_SIZE];
		char assignment[BUF_SIZE];
		char assign_pt[BUF_SIZE];
		FILE * input;
		int assign_total_pts = 0;
		int total_pts = 0;
		static const int num_match = 5;
		regex_t assign;
		regmatch_t pmatch[6];
		int rc;
		int len;

		sprintf(name,argv[2]); /* assign netid into name */
		printf("Grade Info For '%s'\n\n",name);

		sprintf(assign_pt, "(\\:.[a-zA-Z]+.\\|.[0-9]+)");	
		/* TODO - escapes need to get checked */

		/* Open file */
		input = fopen(file,"r");
		if(input)
		{
				printf ( "inside if statement\n" );
				rc = regcomp ( &assign, assign_pt, REG_EXTENDED );
				if ( rc == 0 )
						printf ( "regcomp worked\n" );
				else
				{
						printf ( "regcomp FAILED\n" );
						exit(1);
				}

				while ( fgets ( line, sizeof( line ), input ) )
				{		
						printf ( "inside while loop\n" );
						/* Look for assignment ( : program name | ## ) */
						rc = regexec(&assign, line, num_match, pmatch, 0);
						if(!rc)
						{
								printf ( "inside if statement\n" );
								/* Assignment is found, set what we need */
								len = pmatch[1].rm_eo - pmatch[1].rm_so;
								memcpy(assignment, line + pmatch[1].rm_so, len);
								assignment[len] = '\0';

								len = pmatch[2].rm_eo - pmatch[2].rm_so;
								memcpy(assign_pt, line + pmatch[2].rm_so, len);
								assign_pt[len] = '\0';
								assign_total_pts = atoi(assign_pt);
								total_pts += assign_total_pts;
						}
				}
		}
		else
                {
		/* start looking for these after the else statement
		   - username | ##
		   - username | -## reason
		   - username | reason */
                 }

		regfree(&assign);
		fclose(input);

		return 0;
}
This code is only partially completed, more variables will need to be added as I haven't gotten to parsing the part that handles this:

Assignment : program
-10 no block comments
-20 improper memory use
points : 70 / 100

In the end there will be 4 regex_t's and 4 matching patterns.

Any help on how to solve the file reading problem and then get into the handling of comments for subtracting points from the program grade is appreciated. Thanks.