📄 main.c
字号:
/*
* ARTIFICIAL INTELLIGENCE SYSTEM
*
* Copyright (C) 2007-Present Intelligence Realm Inc. All rights reserved.
*
* See LICENSE.TXT document for licensing information.
*/
#include "main.h"
int main(int argc, char **argv)
{ read_cmu_characters();
return 0;
}
void read_cmu_characters(){ /* read the contents of a text file */
FILE *file_input; char file_name[] = "cmulex.0.6";
char *line = NULL; char buffer[100]; int i = 0;
file_input = fopen(file_name, "r");
if (file_input == NULL) {
printf("Could not open the text file."); abort(); }
line = (char *)malloc(MAX_LINE_LENGTH * sizeof(char));
/* read one line at a time */
while (fgets(line, MAX_LINE_LENGTH, file_input) != NULL)
{ /* skip word duplicates */ if ((substrpos(line, "(") == 0) && (substrpos(line, ")") == 0)) { /* skip comma lines */ if (substrpos(line, "'") == 0) { line = left(line, len(line)-2); for (i=0; i<len(line)-1; i++) { strcpy(buffer, (const char *)line);
printf("INSERT INTO Characters (ID, Character, Source_ID, User_ID) VALUES(NULL, '%c', 1, 1);\n", buffer[i]); } } } }
free(line);
fclose(file_input);
}void read_cmu_words(){ /* read the contents of a text file */
FILE *file_input; char file_name[] = "cmulex.0.6";
char *line = NULL;
file_input = fopen(file_name, "r");
if (file_input == NULL) {
printf("Could not open the text file."); abort(); }
line = (char *)malloc(MAX_LINE_LENGTH * sizeof(char));
/* read one line at a time */
while (fgets(line, MAX_LINE_LENGTH, file_input) != NULL)
{ /* skip word duplicates */ if ((substrpos(line, "(") == 0) && (substrpos(line, ")") == 0)) { /* skip comma lines */ if (substrpos(line, "'") == 0) { line = left(line, len(line)-2);
printf("INSERT INTO Words (ID, Word, Source_ID, User_ID) VALUES(NULL, '%s', 1, 1);\n", line); } } }
free(line);
fclose(file_input);
}int len(char *src){ int l = 0; while(src[l++] != '\0'); return l;}char *left(char *src, int n){ static char *res = NULL; res = src; res[n] = '\0'; return res;}int substrpos(const char *str, const char *substr)
{
/* finds the position of a substring in another string */
char *dest;
int pos;
dest = strstr(str, substr);
if (dest == NULL) /* substring not found */
pos = 0;
else
{
pos = str - dest; /* calculate the position */
if (pos < 0)
pos = -pos; /* take the positive value of position */
}
return pos;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -