| View previous topic :: View next topic |
| Author |
Message |
Jaak Expert Cheater
Reputation: 0
Joined: 02 Jul 2008 Posts: 176
|
Posted: Thu Jan 01, 2009 11:28 am Post subject: [Help] I'm making a Talk Bot |
|
|
I'm making a talk bot which is going to be very basic to start. It will ask certain questions and store the answers for later on. i have a few questions though. Instead of creating 50million variables for every input how can i make it so that it can recieve infinite input and then respond accordingly. I'd also like to beable to make it in the future so that it can detect keywords and then ask a question according to that or respond. I don't want my code to be messy and my main focus right now is making it so that anything can be inputed and then i can work on how to respond to it.
Few questions:
-What libraries should I use? I have the basic iostream and stdlib
-Should i use string or char? Why?
-Can a loop be used to make infite input occur or is there another way?
-(for the future) is it possible for me to detect if a '?' is used and detect keywords so that it can respond or ask a question?
Thank you
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Thu Jan 01, 2009 11:42 am Post subject: |
|
|
If you wan't to store an amount of inputs that isn't fixed to a certain limit you have to keep your input buffer dynamic. Meaning properly allocating and reallocating your buffer.
How you can do this:
HeapAlloc, HeapReAlloc, HeapFree
Include: Windows.h
You should use char, or wchar_t (UNICODE char), or just make it compiler depend and use TCHAR routines.
Include: Tchar.h
If you want to scan for a question mark you can use the handy function _tcsrchr to find the last occurrence of a certain character. In your case a '?'.
Or if you just want it to allow the last character to be a ? then you can check the last character in the buffer.
| Code: | if (Buffer[lstrlen(Buffer)-1] == '?')
... |
And yea, you can loop or you can just have an edit box and a button to allow input, like a send, or enter button. Then you can just filter from your Windows Procedure. (If your using a Window.. If your using console you'll have to stick to looping input).
_________________
|
|
| Back to top |
|
 |
Jaak Expert Cheater
Reputation: 0
Joined: 02 Jul 2008 Posts: 176
|
Posted: Thu Jan 01, 2009 11:46 am Post subject: |
|
|
| lurc wrote: | If you wan't to store an amount of inputs that isn't fixed to a certain limit you have to keep your input buffer dynamic. Meaning properly allocating and reallocating your buffer.
How you can do this:
HeapAlloc, HeapReAlloc, HeapFree
Include: Windows.h
You should use char, or wchar_t (UNICODE char), or just make it compiler depend and use TCHAR routines.
Include: Tchar.h
If you want to scan for a question mark you can use the handy function _tcsrchr to find the last occurrence of a certain character. In your case a '?'.
Or if you just want it to allow the last character to be a ? then you can check the last character in the buffer.
| Code: | if (Buffer[lstrlen(Buffer)-1] == '?')
... |
And yea, you can loop or you can just have an edit box and a button to allow input, like a send, or enter button. Then you can just filter from your Windows Procedure. (If your using a Window.. If your using console you'll have to stick to looping input). |
Wow thank you Im using a console app. (aka: dos window)
1 more question. Can you give an example of code for storing data in the char. thanks
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Thu Jan 01, 2009 12:01 pm Post subject: |
|
|
| Code: | #include <Windows.h>
#include <Tchar.h>
int _tmain(int argc, TCHAR *argv[])
{
LPTSTR lpString = (LPTSTR)HeapAlloc(GetProcessHeap(), 0, sizeof(TCHAR)*MAX_PATH);
if (lpString != NULL)
{
_tscanf(_T("%s"), lpString); // Don't remember if this catchs spaces...
_tprintf(_T("You inputted: %s"), lpString);
HeapFree(GetProcessHeap(), 0, (LPVOID)lpString);
}
return 0;
} |
Although, I recommend you use ReadConsole.
First parameter can be obtained by GetStdHandle.
_________________
|
|
| Back to top |
|
 |
Jaak Expert Cheater
Reputation: 0
Joined: 02 Jul 2008 Posts: 176
|
Posted: Thu Jan 01, 2009 12:03 pm Post subject: |
|
|
| lurc wrote: | | Code: | #include <Windows.h>
#include <Tchar.h>
int _tmain(int argc, TCHAR *argv[])
{
LPTSTR lpString = (LPTSTR)HeapAlloc(GetProcessHeap(), 0, sizeof(TCHAR)*MAX_PATH);
if (lpString != NULL)
{
_tscanf(_T("%s"), lpString); // Don't remember if this catchs spaces...
_tprintf(_T("You inputted: %s"), lpString);
HeapFree(GetProcessHeap(), 0, (LPVOID)lpString);
}
return 0;
} |
Although, I recommend you use ReadConsole.
First parameter can be obtained by GetStdHandle. |
Uhh.. I really don't know what all of that means but ill keep working and post when i have problems. thanks
|
|
| Back to top |
|
 |
92Garfield I'm a spammer
Reputation: 57
Joined: 20 Dec 2007 Posts: 5871 Location: Banana Republic Germany
|
Posted: Thu Jan 01, 2009 12:44 pm Post subject: |
|
|
You should use an array i guess
And you should already know what it is...
_________________
|
|
| Back to top |
|
 |
Jaak Expert Cheater
Reputation: 0
Joined: 02 Jul 2008 Posts: 176
|
Posted: Thu Jan 01, 2009 3:48 pm Post subject: |
|
|
| 92Garfield wrote: | You should use an array i guess
And you should already know what it is... |
Why should I? What if I didn't? how can you assume what i already know...
Ontopic: For those who don't know what im making, this is similiar to an AIM bot. If you want an example google "igod"
|
|
| Back to top |
|
 |
|