+/EE312
software design
git clone https://git.julia.blue/+/EE312
f830e85
master
1 2#define _CRT_SECURE_NO_WARNINGS 1 // this #define is for VS2012, which doesn't like the standard C library 3 4#include <stdio.h> // declaraations of standard input/output functions 5#include <stdint.h> // declarations of standard integer types (e.g., int32_t) 6#include <stdlib.h> // declarations of general functions in the standard library (e.g., abort, exit) 7 8 9#define ONE_MB (1 << 20) 10#define BUFFER_SIZE ONE_MB 11 12char dictionary [BUFFER_SIZE ];// a large buffer to hold a dictionary (1MB) 13char article [BUFFER_SIZE ];// a large buffer to hold an article (1MB) 14 15void spellCheck (char [],char []);// this is the function you write (put your function in Project1.cpp 16 17/* 18* Read a .txt file into one of the two buffers 19* this function does NOT confirm that the file is correctly formatted 20*/ 21void readFile (const char file_name [],char buffer []) { 22FILE * file = fopen (file_name ,"r" ); 23if (file == 0 ) { 24printf ("unable to open file \"%s\"\n" ,file_name ); 25abort (); 26 } 27 28/* clear (set to zeros) the buffer */ 29for (uint32_t k = 0 ;k < BUFFER_SIZE ;k += 1 ) { 30buffer [k ]= 0 ; 31 } 32 33/* read the file (this is a binary read, which is OK) */ 34uint32_t bytes_read = fread (buffer ,1 ,BUFFER_SIZE ,file ); 35buffer [bytes_read ]= 0 ; 36} 37 38void fruityTest (void ) { 39printf ("\n\n******* Starting Base Test #1 (fruity) *******\n" ); 40char dictionary []= "apple\nbanana\norange\npear\n" ; 41char article []= "I ate an apple and a pear\n" ; 42spellCheck (article ,dictionary );// should print: ate, an, and 43printf ("****DONE****\n" ); 44} 45 46void dogTest (void ) { 47printf ("\n\n******* Starting Base Test #2 (dogs) *******\n" ); 48char dictionary []= "Beagle\nBulldog\nCollie\nPoodle\nretriever\n" ; 49char article []= "bulldog dalmation beagle Retriever poodles" ; 50spellCheck (article ,dictionary );// should print: dalmation poodles 51printf ("****DONE****\n" ); 52} 53 54void punctuationTests (void ) { 55printf ("\n\n******* Starting Base Test #3 (punctuation) *******\n" ); 56char dictionary []= "but\ncan\ncan't\ndo\ndon't\nthink\n" ;// the dictionary can contain punctuation 57char article []= "I think I can, but I can't. I think I do, but I don't" ; 58spellCheck (article ,dictionary );// should print: don 59printf ("****DONE****\n" ); 60} 61 62void generalTest1 (void ) { 63printf ("\n\n******* Starting General Test #1 *******\n" ); 64readFile ("greek-finances.txt" ,article ); 65readFile ("american-english.txt" ,dictionary ); 66spellCheck (article ,dictionary ); 67printf ("****DONE****\n" ); 68} 69 70void generalTest2 (void ) { 71printf ("\n\n******* Starting General Test #2 *******\n" ); 72readFile ("bobsledding.txt" ,article ); 73readFile ("american-english.txt" ,dictionary ); 74spellCheck (article ,dictionary ); 75printf ("****DONE****\n" ); 76} 77 78/* you should also make your own tests! */ 79int main (void ) { 80/* for starters, uncomment the following tests, one at a time */ 81fruityTest (); 82dogTest (); 83punctuationTests (); 84generalTest1 (); 85generalTest2 (); 86}