1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
#include <stdio.h>
#include <conio.h>
#include <windows.h>
#define ARRAYSIZE(sel) (sizeof(sel) / sizeof(sel[0]))
#define MAX 1000
#define SELECT_END 2
#define KEY_UP 72
#define KEY_DOWN 80
#define KEY_ENTER 13
#define KEY_ESCAPE 27
void regName();
void hideCursor();
void selector(unsigned int select);
int main()
{
hideCursor();
int select = 0;
int x;
selector(select);
while((x = _getch()))
{
if(x == KEY_UP)
{
select -= 2;
if(select < 0)
select = 0;
selector(select);
}
else if(x == KEY_DOWN)
{
select += 2;
if(select > SELECT_END)
select = SELECT_END;
selector(select);
}
else if(x == KEY_ENTER)
{
if(select <= 1)
{
regName();
selector(select);
}
else if(select <= 2)
{
printf("\n\n\n\n\t Exit program");
Sleep(1500);
exit(0);
}
}
}
}
void selector(unsigned int select)
{
const char *selection[] =
{
"\n\n\t [REGISTER NAME]",
"\n\n\t register name",
"\n\t [EXIT]",
"\n\t exit",
};
unsigned int i;
system("cls");
printf("\n\n\t\tMENU\n\t\t----\n\n");
for(i = 0; i < ARRAYSIZE(selection); i += 2)
{
if(i == select)
printf("%s\n", selection[i]);
else
printf("%s\n", selection[i + 1]);
}
}
void hideCursor()
{
HANDLE cursorHandle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO info;
info.dwSize = 100;
info.bVisible = FALSE;
SetConsoleCursorInfo(cursorHandle, &info);
}
void regName()
{
BOOL found = FALSE;
FILE *file;
char fname[MAX] = "Name.txt";
char name[MAX];
char temp[MAX];
file = fopen(fname, "a+");
system("cls");
printf("\n\n\tEnter name: ");
scanf("%20s", temp);
fseek(file, 0, SEEK_END);
long size = ftell(file);
do
{
rewind(file);
while(fscanf(file, "%20s", name) == 1)
{
if(strcmp(temp, name) == 0)
{
found = TRUE;
printf("\n\n\t Name already exists.");
Sleep(1500);
system("cls");
fclose(file);
return;
}
}
if(!found)
{
rewind(file);
fprintf(file, "%s\n", temp);
printf("\n\n\t Name registered.");
Sleep(1500);
system("cls");
fclose(file);
return;
}
}while(size != 0);
}
|