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

#define LOG_FILE_NAME	"t6_file.log"
#define MSG_SIZE	80
#define TRUE		1
#define FALSE		0

int main() {
	FILE *fp_out;
	char s[MSG_SIZE];
	time_t t;
	int exit = FALSE;
	char c;

	fp_out = fopen(LOG_FILE_NAME, "a");
	if (fp_out == NULL) {
		return -1;
	}

	printf("Log file management. Type \"quit\" to quit.\n");
	do {
		printf("What do you want to add to the log?\n");
		scanf("%[^\n]%*c", s);
		// sense "%*c" el '\n' es quedaria en el stdin per sempre
		// Si poseu "\n" enlloc de "%*c" tambe es queda encallat. :-?
		printf("[%s]\n", s);
		if (strcmp("quit", s) == 0) {
			exit = TRUE;
		} else {
			time(&t);
			fprintf(fp_out, "%s\t%s\n", ctime(&t), s);
			fflush(fp_out);
		}
	} while (!exit);

	fclose(fp_out);

	return 0;
}

