ctdl
ctdl
h>
#include <string.h>
#include <stdbool.h> // Thêm thu vi?n này d? s? d?ng ki?u d? li?u bool
#include <stdlib.h> // Thêm thu vi?n này d? s? d?ng hàm `remove`
struct WORD
{
char Name[256];
char Meaning[512];
};
void Output_Word(WORD a)
{
printf("Name:%s\n", a.Name);
printf("Meaning:%s\n", a.Meaning);
}
fclose(file);
}
WORD word;
while (fscanf(file, "%255[^|]|%511[^\n]\n", word.Name, word.Meaning) == 2)
{
if (strcmp(word.Name, searchName) == 0)
{
strcpy(word.Meaning, newMeaning);
}
Write_Word_To_File(tempFile, word);
}
fclose(file);
fclose(tempFile);
remove(filename);
rename("temp.txt", filename);
}
WORD word;
while (fscanf(file, "%255[^|]|%511[^\n]\n", word.Name, word.Meaning) == 2)
{
if (strcmp(word.Name, searchName) != 0)
{
Write_Word_To_File(tempFile, word);
}
}
fclose(file);
fclose(tempFile);
remove(filename);
rename("temp.txt", filename);
}
while (check)
{
printf("0.Thoat\n");
printf("1.Input word\n");
printf("2.Output word\n");
printf("3.Input wordlist\n");
printf("4.Output wordlist\n");
printf("5.Sort wordlist\n");
printf("6.Search word by Name\n");
printf("7.Write a word to file\n");
printf("8.Read a word from file\n");
printf("9.Update Meaning in file\n");
printf("10.Delete word from file\n");
printf("11.Write wordlist to file\n");
case 9:
{
char updateName[256];
char newMeaning[512];
printf("Nhap ten can cap nhat: ");
fflush(stdin);
fgets(updateName, sizeof(updateName), stdin);
updateName[strlen(updateName) - 1] = '\0'; // Lo?i b? ký t? '\n' th?a
t? fgets
printf("Nhap nghia moi: ");
fflush(stdin);
fgets(newMeaning, sizeof(newMeaning), stdin);
newMeaning[strlen(newMeaning) - 1] = '\0'; // Lo?i b? ký t? '\n' th?a
t? fgets
FILE *file = fopen(filename, "r+");
if (file != NULL)
{
Update_Meaning_In_File(file, updateName, newMeaning, filename);
fclose(file);
}
break;
}
case 10:
{
char deleteName[256];
printf("Nhap ten can xoa: ");
fflush(stdin);
fgets(deleteName, sizeof(deleteName), stdin);
deleteName[strlen(deleteName) - 1] = '\0'; // Lo?i b? ký t? '\n' th?a
t? fgets
FILE *file = fopen(filename, "r+");
if (file != NULL)
{
Delete_Word_From_File(file, deleteName, filename);
fclose(file);
}
break;
}
case 11:
Write_WordList_To_File(many, n, filename);
break;
default:
break;
}
}
return 0;
}