#include #include #include #define STRING_SIZE 250 /* data types */ typedef struct list_node_struct { char node_string[STRING_SIZE]; /* string held in this node */ struct list_node_struct *next; /* pointer to next node */ } list_node; typedef list_node *string_list; /* function headers */ string_list create_list(); int add_string(string_list *l, char *s); void print_list(string_list l); int search_string(string_list l, char *s); int delete_string(string_list *l, char *s); void clean_list(string_list *l); void encrypt_string(char *s, int k); void encrypt_list(string_list l, int k); /* main command parser */ int main() { char buffer[2*STRING_SIZE], command[2*STRING_SIZE], string[2*STRING_SIZE]; char *word; string_list sl = create_list(); int offset; while(1) { printf("Enter a command: "); fgets(buffer,sizeof(buffer),stdin); word = strtok(buffer," \t\n"); strcpy(command, word); word = strtok(NULL,"\n"); if( word != NULL ) strcpy(string, word); if (strcmp(command,"end") == 0) { clean_list(&sl); printf("Thanks, it's been fun.\n"); return 0; } else if (strcmp(command,"print") == 0) { print_list(sl); } else if (strcmp(command,"add") == 0) { if (add_string(&sl,string)) printf("Add successful!\n\n"); else printf("Add unsuccessful.\n\n"); } else if (strcmp(command,"delete") == 0) { if (delete_string(&sl,string)) printf("Delete successful!\n\n"); else printf("Delete unsuccessful.\n\n"); } else if (strcmp(command,"search") == 0) { printf("The string '%s' is ", string); if (!search_string(sl,string)) printf("not "); printf("in the list.\n\n"); } else if (strcmp(command,"encrypt") == 0) { offset = atoi(string); if (offset <= 0) { printf("Encryption unsuccessful.\n\n"); } else { encrypt_list(sl,offset); printf("Encryption successful!\n\n"); } } else if (strcmp(command,"clean") == 0) { clean_list(&sl); printf("List has been cleaned.\n\n"); } else { printf("Couldn't understand your command.\n\n"); } } } /* Your functions should go here */