#include "memo.h"


clean_memos()
{
	FILE *nfp;
	char nmfile[128];
	long stop_t, start_t, repeat_t;
	char text[MAXLINE];
	int i;

	if ((fp = fopen(mfile, "r")) == NULL) {
		fprintf(stderr, "memo: can't open memo file %s\n", mfile);
		exit(1);
	}
	get_temp_file(nmfile);
	if ((nfp = fopen(nmfile, "w")) == NULL) {
		fprintf(stderr, "memo: can't open temp file %s\n", nmfile);
		exit(1);
	}
	for (i=1; fscanf(fp, "%ld%ld%ld", &start_t, &stop_t, &repeat_t) != EOF && fgets(text, MAXLINE, fp) != NULL; i++) {	
		if (stop_t > time(0) || stop_t == 0 || repeat_t != 0)
			fprintf(nfp, "%ld %ld %ld%s", start_t, stop_t, repeat_t, text);
	}
	fclose(nfp);
	fclose(fp);
	flip_files(mfile, nmfile);
}
