Question: General: This first big project will give you a chance to dust off all the cobwebs on your programming skills. The project requires that you
General: This first big project will give you a chance to dust off all the cobwebs on your programming skills. The project requires that you understand characters and strings, arrays, functions, loops and conditionals (all prerequisite knowledge). However, just because this is technically "a review", don't assume it's easy! You'll write a very simple spell checker. You must produce the output EXACTLY as specified in this document. There is some flexibility permitted in your solution to encourage you to adopt your own ideas for an algorithm. The limits to that flexibility are explained below. Any extra output, or output that is inconsistent with these requirements will result in lost points. Your Mission: Edit the file "Project1.cpp". You must implement the function printSuperStrings. You may find it useful to write several other functions as well. In fact, I encourage you to avoid writing the whole project as one big (ugly) function. You will find big (ugly) functions are very difficult to debug, and we will find it very difficult to help you. For this assignment, you should keep all your functions in one file -- Project1.cpp. They should all be C, and you should not use C++-only features. For the purpose of this assignment, a superstring S of a string s is a char array such that if we remove 0 or more chars from S, we get s. Examples: superstrings of hello: hello, xhxexlxlox, helolo non-superstrings of hello: helo, helon, sandwich S and s consist of only letters, upper- and lower-case. A word is a sequence of one or more letters with no intervening whitespace. Whitespace characters can occur anywhere -- at the start, just before the final null termination, or anywhere between words. Characters are case-sensitive. There is only one stage on this project, writing the printSuperStrings routine. The printSuperStrings function has two parameters. The first parameter (strings[]) is a pointer to an array of characters. The contents of this array are a list of words that you need to spell check. Words in strings are separated by spaces, tabs, and possibly newlines. The end of the article is marked with the normal '\0' (marking the end of a C-string). The second parameter of the function (superstrings[]) is a pointer to another array of chars similar to strings. Your function must print every word in superstrings that is a superstring of every word in strings, in order.
Finding words is easy. Just look for a letter, thus marking the beginning, and keep scanning for consecutive letters. When you run out of letters, that marks the end. For each word in strings, you must go through superstrings to print all the superstrings of that word, each accompanied by a newline. Do not print empty lines, except perhaps for the very last line in your output. You can print the words in several ways, depending on how you store the words in memory. If the word is terminated with a 0 like a regular string, then you can use printf: printf("%s", word); If your strings are not terminated with the zero, then you will need to print them one letter at a time (using a loop). You can print a single letter in one of two ways: printf("%c", letter); or putchar(letter); When you're debugging your program, you will want to make sure that all the characters you have printed show up on the screen. That may sound silly, but it is a real problem. The computer does not always put characters on the screen, even if you've used printf or putchar to print them! If you want to make sure characters have been forced to the screen, print a new line (" ") or use fflush(stdout). Bounds on input: strings and superstrings may each have up to 5000 words. Each word is at most 19 chars long, not including any null termination or whitespace. Your program should run in on mario or your laptop. Output Requirements: Your function must only print the superstring words from superstrings. Each word that you print must be printed on a line by itself (i.e., you must print a ' ' after each word of output). You may print words in the same case as they appear in superstrings. Please keep in mind that we will test your program with different strings and different superstrings than have been provided to you. Your program should work with any strings or superstrings that satisfies the requirements listed above. Not all strings start with a letter or end with a letter. Not all strings have at least one word. Not all superstrings have at least one word.
given
#define ONE_MB (1
#define BUFFER_SIZE ONE_MB
char superstrings[BUFFER_SIZE]; // a large buffer to hold a dictionary (1MB)
char strings[BUFFER_SIZE]; // a large buffer to hold an strings (1MB)
void printSuperStrings(char target [], char candidates []); // this is the function you write
/*
* Read a .txt file into one of the two buffers
* this function does NOT confirm that the file is correctly formatted
*/
void readFile(const char file_name[], char buffer[]) {
FILE* file = fopen(file_name, "r");
if (file == 0) {
printf("unable to open file \"%s\" ", file_name);
abort();
}
/* clear (set to zeros) the buffer */
for (uint32_t k = 0; k
buffer[k] = 0;
}
/* read the file (this is a binary read, which is OK) */
uint32_t bytes_read = fread(buffer, 1, BUFFER_SIZE, file);
buffer[bytes_read] = 0;
}
void simpleTest(void) {
printf("******* Starting Base Test #1 (simpleTest) ******* ");
char superstrings[] = "bulldogx bulldog bulldo ulldog xbullxdogxx bulsdf abuxllORdoxgM ulld";
char strings[] = "bulldog bulld";
printSuperStrings(strings, superstrings); // should print: don
printf("****DONE**** ");
}
void generalTest(void) {
printf(" ******* Starting General Test #2 ******* ");
readFile("strings1.txt", strings);
readFile("superstrings1.txt", superstrings);
printSuperStrings(strings, superstrings);
printf("****DONE**** ");
}
/* you should also make your own tests! */
int main(void) {
/* for starters, uncomment the following tests, one at a time */
simpleTest();
generalTest();
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
