I have my code to compare words now:
Code:
// crt_strtok_s.c
// In this program, a loop uses strtok_s
// to print all the tokens (separated by commas
// or blanks) in two strings at the same time.
//
#include <string.h>
#include <stdio.h>
char string1[] =
"house dog ran";
char seps[] = " ,\t\n";
char *token1,
*next_token1;
int main( void )
{
// Establish string and get the first token:
token1 = strtok_s( string1, seps, &next_token1);
// While there are tokens in "string1" or "string2"
while (token1 != NULL)
{
// Get next token:
if (token1 != NULL)
{
token1 = strtok_s( NULL, seps, &next_token1);
if ((strcmp(token1, "house")) || (strcmp(token1, "dog"))){
printf("Ok, so it is one of the expected nouns.\n");
}
if ((strcmp(1+token1, "run")) || (strcmp(1+token1, "ran"))){
printf("Ok, so it is one of the expected verbs.\n");
}
getch();
return 0;
}
}
}
Which gives this answer;
Code:
Ok, so it is one of the expected nouns.
Ok, so it is one of the expected verbs.
As far as having the structure make sense I have a plan. Break the order into chunks of: subject, verb, object, or subject, verb, or exclamation word.
This means I will need four if's: noun, verb, object, exclamation. Like the code below which has three if's.
Code:
// crt_strtok_s.c
// In this program, a loop uses strtok_s
// to print all the tokens (separated by commas
// or blanks) in two strings at the same time.
//
#include <string.h>
#include <stdio.h>
char string1[] =
"sam ate oranges";
char seps[] = " ,\t\n";
char *token1,
*next_token1;
int main( void )
{
// Establish string and get the first token:
token1 = strtok_s( string1, seps, &next_token1);
// While there are tokens in "string1" or "string2"
while (token1 != NULL)
{
// Get next token:
if (token1 != NULL)
{
token1 = strtok_s( NULL, seps, &next_token1);
if ((strcmp(token1, "house")) || (strcmp(token1, "sam"))){
printf("Ok, so it is one of the expected subjects.\n");
}
if ((strcmp(1+token1, "run")) || (strcmp(1+token1, "ate"))){
printf("Ok, so it is one of the expected verbs.\n");
}
if ((strcmp(1+token1, "run")) || (strcmp(1+token1, "oranges"))){
printf("Ok, so it is one of the expected objects.\n");
}
getch();
return 0;
}
}
}
Which gives this answer:
Code:
Ok, so it is one of the expected subjects.
Ok, so it is one of the expected verbs.
Ok, so it is one of the expected objects.