Bienvenue,
Ce forum est fait pour poser des questions précises sur des sujets précis, pas pour demander des codes tout faits.
Néanmoins, voilà une piste de code.
#include <stdio.h>
#include <string.h>
int DisplayHelp(char* lpWord)
{
FILE* lpFile;
char lpFileName[50];
char lpBuffer[2000];
long nSize;
strcpy(lpFileName, lpWord);
strcat(lpFileName, ".txt");
lpFile = fopen(lpFileName, "rb");
if (lpFile)
{
printf("%s\n", lpWord);
fseek(lpFile, 0, SEEK_END);
nSize = ftell(lpFile);
fseek(lpFile, 0, SEEK_SET);
fread(lpBuffer, 1, nSize, lpFile);
lpBuffer[nSize] = 0;
puts(lpBuffer);
fclose (lpFile);
puts("===================");
}
return (int)lpFile;
}
int IsAlpha(char nChar)
{
return (((nChar >= 'a') && (nChar <= 'z')) || ((nChar >= 'A') && (nChar <= 'Z')));
}
int main()
{
char lpQuestion[500];
char lpWord[50];
int nLen;
int nBeginning;
int bUnderstood;
int nI;
while (1)
{
printf("Question ?\n");
gets(lpQuestion);
/* On quitte si rien de tapé */
if (! strcmp(lpQuestion, ""))
break;
/* On s'assure d'avoir un caractère spécial à la fin */
strcat(lpQuestion, ".");
nLen = strlen(lpQuestion);
nBeginning = 0;
bUnderstood = 0;
for (nI = 0; nI < nLen; nI++)
{
if (! IsAlpha(lpQuestion[nI]))
{
if (nI != nBeginning)
{
memcpy(lpWord, &lpQuestion[nBeginning], nI - nBeginning);
lpWord[nI - nBeginning] = 0;
if (DisplayHelp(lpWord))
{
bUnderstood = 1;
break;
}
}
nBeginning = nI + 1;
}
}
if (! bUnderstood)
printf("Désolé, je n'ai pas compris la question.\n");
}
return 0;
}