Hi,
I'm having two problems with my code. One is implenting enumeration into it....And the other (which is frustrating because it's USUALLY easy to do) is getting it to exit when the user does not enter anything.
To better describe my enumeration problem....I have to implement the line that is currently in comment
//enum strfunct {strcat, strchr, strcpy, strcmp, strlen, strstr, strtok};
Right now it compiles and runs fine (Except for the exiting thing), but I have to use enumeration for the string functions. Any help would be appreciated.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
enum boolean {FALSE = 0, TRUE = 1};
//enum strfunct {strcat, strchr, strcpy, strcmp, strlen, strstr, strtok};
int main(void)
{
int i;
enum boolean Found;
enum strfunct fct;
char string[50];
char *str_names[] = {
"strcat",
"strchr",
"strcmp",
"strcpy",
"strlen",
"strstr",
"strtok"
};
//get user string and compare it with string names
printf( "Enter a possible C string function: " );
gets (string);
do
{
Found = FALSE;
//compare and see if they're equals
for (i=0; i<7; i++)
{
if (strcmp(string,str_names[i]) == 0)
{
Found = TRUE;
}
else if (strcmp(string,str_names[i]) == 1)
{
Found = FALSE;
}
}
if (Found == TRUE)
{
printf("%s is a C defined string function\n",string);
}
else if (Found == FALSE)
{
printf("%s is NOT a C defined String function\n", string);
}
printf( "\nNext function, please: " );
gets (string);
}
while (string != NULL);
return 0;
}



LinkBack URL
About LinkBacks


