Skip to content

Instantly share code, notes, and snippets.

@toanalien
Created June 4, 2015 18:50
Show Gist options
  • Save toanalien/ac77e53fb5bea2f4a5e2 to your computer and use it in GitHub Desktop.
Save toanalien/ac77e53fb5bea2f4a5e2 to your computer and use it in GitHub Desktop.
Took phrases from the dictionary file
/**
* download dictionary file at http://blackberryvietnam.net/threads/du-lieu-tu-dien-cho-ung-dung-ddict.897/
*/
#include <stdio.h>
#include <string.h>
int main()
{
char s[300];
char *s1,*s2,*s3;
char en[300],vi[300];
FILE *src_file, *des_file;
src_file = fopen("av.dd", "r");
des_file = fopen("av.dd.txt", "w+");
while (fgets(s, 300, src_file) != nullptr)
{
s1 = strstr(s, "##");
if (s1 != nullptr)
{
strncpy(en, s, strlen(s) - strlen(s1));
en[strlen(s) - strlen(s1)] = '\0';
s2 = strstr(s1, "|-");
if (s2!= nullptr)
{
s3 = strstr(s2+3, "|");
if (s3!=nullptr)
{
strncpy(vi, s2 + 3, strlen(s2) - strlen(s3) - 3);
vi[strlen(s2) - strlen(s3) - 3] = '\0';
strcat(en, "#");
strcat(en, vi);
fputs(en, des_file);
fputs("\n", des_file);
}
else
{
strcat(en, "#");
strcat(en, s2 + 3);
fputs(en, des_file);
}
}
}
}
rewind(des_file);
fclose(src_file);
getchar();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment