I have a chatbot program that uses a function called userInput()
to get the input from the user.
I have to test the program for my project but I don't know how to input text into the function in the test program. Everything I have tried has stopped the automatic testing waiting for the user to type something.
Any help adding test phrases the user would say without stopping the testing program.
char *userInput()
{
char *str = NULL;
int ch;
size_t size = 0, len = 0;
while ((ch=getchar()) != EOF && ch != '\n') {
if (len + 1 >= size)
{
size = size * 2 + 1;
str = realloc(str, sizeof(char)*size);
}
str[len++] = ch;
}
if (str != NULL) {
str[len] = '\0';
}
return str;
}
I ran with anonmess's idea that you can input text from the user using an input file. I used an input file with the following lines:
The input file name is given through the command line. You can hard code the filename if you'd like.
The file is read and the lines are printed. You can pass the string to another function within the while loop.