допестим, что словарь у тебя как текстовый файл. слова идут друг за дружкой разделены символом переноса каретки.
программу пишу без проверок на открытие файла и так делее. Это не связано со строками. разберешся.
| Код |
#include "stdio.h" #include "string.h"
char** searchByKey(char *key) { FILE *dsc = fopen("dict","r"); size_t read_bytes(1); char *str,**hash; int hash_size(0),size(0); while (read_bytea !=0) { read_bytes = fread(str,256,1,dsc); fseek(dsc,read_bytes,SEEK_CUR); if (strstr(str,key) != NULL) { *hash = (char **)realloc(hash,hash_size+=strlen(str)); hash[size] = (char *)malloc(strlen(str)); strcpy(hash[size++],str); } } *hash = (char **)realloc(hash,sizeof(NULL)); hash[size] = (char *)malloc(sizeof(NULL)); strcpy(hash[size],NULL); } int main() { char **found, *key; sccanf("%s",key); found = searchByKey(key); for(int i=0;found[i]!=NULL;i++) { printf("%s\n",found[i]); } }
|
это все вроде должно работать. не проверял, писал сразу в форум |