Skip to content

Instantly share code, notes, and snippets.

@itsjef
Created July 17, 2013 09:13
Show Gist options
  • Save itsjef/6019029 to your computer and use it in GitHub Desktop.
Save itsjef/6019029 to your computer and use it in GitHub Desktop.
Game về từ ngữ các kiểu ....
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX 1000
typedef struct dictionary{
char word[20];
char def[50];
float point;
}DICTIONARY;
DICTIONARY list[MAX];
int numrecords = 0;
char filename[] = "Dictionary.txt";
void manageWord();
void menu()
{
char choice;
system("cls");
printf(" ---TRO CHOI DOAN TU---\n"
"==================================================================\n"
"\n\n1. Quan Ly Tu\n2. Doan Tu\n3. Thong Ke\n0. Thoat\n\nLua Chon: ");
fflush(stdin);
scanf("%c",&choice);
switch(choice)
{
case '1':
manageWord();
break;
case '2':
// guessWord();
break;
case '3':
// result();
break;
case '0':
printf("\nBan da thoat khoi chuong trinh!!!!\nHen gap lai!!!");
break;
}
}
void addNewWord()
{
int i, point;
char choice;
system("cls");
FILE *fp;
fp = fopen("Dictionary1.txt","a+");
printf(" ---TRO CHOI DOAN TU---\n"
"==================================================================\n"
" THEM TU MOI\n"
"==================================================================\n");
fflush(stdin);
printf("\nTu: ");
gets(list[numrecords].word);
fflush(stdin);
printf("Goi y: ");
gets(list[numrecords].def);
fflush(stdin);
printf("Diem: ");
scanf("%f",&point);
list[numrecords].point = point;
fflush(stdin); if(fp != NULL)
{
fprintf(fp, "%s;",list[numrecords].word);
fprintf(fp, "%s;",list[numrecords].def);
fprintf(fp, "%.1f\n",point);
fclose(fp);
}
fclose(fp);
printf("Ban muon tiep tuc ? (C/K)");
fflush(stdin);
scanf("%c",&choice);
switch(choice)
{
case 'C':
case 'c':
addNewWord();
break;
case 'K':
case 'k':
manageWord();
break;
}
}
void deleteWord()
{
int i, found, dump[MAX];
char word[20], wordTemp[20],def[50],defTemp[50];
char choice;
system("cls");
printf(" ---TRO CHOI DOAN TU---\n"
"==================================================================\n"
" XOA TU\n"
"==================================================================\n");
fflush(stdin);
printf("Tu can xoa: ");
scanf("%[^\n]",word);
fflush(stdin);
printf("Goi y: ");
scanf("%[^\n]",def);
i = found = 0;
do{
strcpy(wordTemp,list[i].word);
strcpy(defTemp,list[i].def);
if(strcmp(strlwr(word),strlwr(wordTemp)) == 0&&strcmp(strlwr(def),strlwr(defTemp)) == 0)
dump[found++] = i;
i++;
} while(i < numrecords);
for(found = dump[i] - 1; found < numrecords - 1; found++)
list[found] = list[found + 1];
numrecords--;
//list[numrecords - 1].word = del;
printf("Xoa thanh cong!!!\nBan co muon xoa tiep ? (C/K)");
fflush(stdin);
scanf("%c",&choice);
switch(choice)
{
case 'C':
case 'c':
deleteWord();
break;
case 'K':
case 'k':
//manageWord();
break;
}
}
void manageWord()
{
int i, temp = 1;
float point;
char choice;
char word[20],def[50];
system("cls");
FILE *fp;
fp = fopen("Dictionary1.txt","r");
printf(" ---TRO CHOI DOAN TU---\n"
"==================================================================\n"
" DANH SACH TU\n"
"==================================================================\n"
"+---+-------------+----------------------------------------+-----+\n"
"|STT| TU | GOI Y | Diem|\n"
"+---+-------------+----------------------------------------+-----+\n");
while (fscanf(fp,"%15[^;];%30[^;];%f", word, def, &point) == 3)
printf("%s%s%.1f", word, def, point);
printf("\n+---+-------------+----------------------------------------+-----+\n"
"1. Them moi | 2. Chinh sua | 3. Xoa bo | 0. Quay lai\n\nLua Chon: ");
fflush(stdin);
scanf("%c",&choice);
switch(choice)
{
case '1':
addNewWord();
break;
case '2':
break;
case '3':
deleteWord();
break;
case '0':
menu();
break;
}
}
int main()
{
menu();
getch();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment