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

void read(char *res, int maxsize);

struct Person {
   char  name[28];
   int   age;
};
 
void printPerson(struct Person *p) {
	printf("%s is %d years old\n", p->name, p->age);
}

void readPerson(struct Person *p) {
    printf("Enter your name: ");
    fflush(stdout);
    read(p->name, sizeof p->name);

	do {
		printf("Enter your age: ");
		fflush(stdout);
		scanf("%d", &p->age);
	} while (p->age < 0);
}


void read(char *res, int maxsize) {
	/* initialize each element to 0 to ensure that the result is null terminated */
	char buffer[1024] = {0};
	int ch;
	int i = 0;

	// break on newline, max size or end-of-file
	while((ch=getchar()) != '\n' && i < maxsize)
	{
	   if (ch == EOF) break;
	   buffer[i++] = ch;
	}

	memcpy(res, buffer, maxsize);
}

void greet() {
	struct Person p;

	char flag[32];	
	strcpy(flag, "CSC{K03k735_Z1jn_73kker}"); 

	readPerson(&p);
    printPerson(&p);

	if (strcmp(p.name, flag) == 0) {
		printf("Wauw, you have the same name as our flag!");
	}
}

int main()
{
	greet();
	return 0;
}
