@@ -15,39 +15,62 @@ int isUpperCaseLetter(int iochar);
1515void duplicateArray (char s1 [S1LENGTH + 1 ], char s3 [S1LENGTH + 1 ]);
1616
1717int main (void ) {
18- 19- /* Generate a random pattern of uppercase letters */
20- char s1 [S1LENGTH + 1 ];
21- generateS1 (s1 );
18+ printf ("Welcome User" );
19+ char selection = 'Y' ;
20+ int invalidSelectionFlag ;
21+ 22+ while (selection == 'Y' || selection == 'y' ) {
23+ /* Reset invalidSelectionFlag */
24+ invalidSelectionFlag = 0 ;
2225
23- /* Get user string of uppercase letters */
24- char s2 [ S2LENGTHMAX ];
25- generateS2 ( s2 );
26+ /* Generate a random pattern of uppercase letters */
27+ char s1 [ S1LENGTH + 1 ];
28+ generateS1 ( s1 );
2629
27- /* Get replacement character from user */
28- char ch = getReplacementCharacter ();
30+ /* Get user string of uppercase letters */
31+ char s2 [S2LENGTHMAX ];
32+ generateS2 (s2 );
2933
30- /* Before we modify s1, we'll create a copy of s1 called original */
31- char original [S1LENGTH + 1 ];
32- duplicateArray (s1 , original );
34+ /* Get replacement character from user */
35+ char ch = getReplacementCharacter ();
3336
34- /* Search s1 and replaces any occurrences of any of the characters contained in s2 with character ch */
35- strfilter (s1 , s2 , ch );
37+ /* Before we modify s1, we'll create a copy of s1 called original */
38+ char original [S1LENGTH + 1 ];
39+ duplicateArray (s1 , original );
3640
37- /* Output */
38- printf ("s1 = " );
39- puts (original );
41+ /* Search s1 and replaces any occurrences of any of the characters contained in s2 with character ch */
42+ strfilter (s1 , s2 , ch );
4043
41- printf ("s2 = " );
42- puts (s2 );
44+ /* Print the original string, user string, user char, and filtered string */
45+ printf ("s1 = " );
46+ puts (original );
4347
44- printf ("ch = '%c'\n" , ch );
48+ printf ("s2 = " );
49+ puts (s2 );
4550
46- printf ("s3 = " );
47- puts (s1 );
51+ printf ("ch = '%c'\n" , ch );
4852
53+ printf ("s3 = " );
54+ puts (s1 );
4955
56+ /* Prompt the user the restart the program */
57+ do {
58+ printf ("\nWould you like to run the program again? Type 'Y' for Yes, enter 'N' to exit\n" );
59+ selection = getchar ();
5060
61+ if (getchar () != '\n' ) {
62+ while (getchar () != '\n' ) {}
63+ invalidSelectionFlag = 1 ;
64+ }
65+ else {
66+ if (selection == 'Y' || selection == 'y' || selection == 'N' || selection == 'n' ) {
67+ invalidSelectionFlag = 0 ;
68+ }
69+ }
70+ } while (invalidSelectionFlag );
71+ }
72+ 73+ printf ("\nTerminating Program..\n" );
5174 return 0 ;
5275}
5376
@@ -74,7 +97,7 @@ void generateS1(char s1[S1LENGTH + 1]) {
7497
7598int generateS2 (char s2 [S2LENGTHMAX + 1 ]) {
7699 /* Get the user string */
77- printf ("Enter a string of uppercase letters 'A' - 'Z'\n" );
100+ printf ("\nEnter a string of uppercase letters 'A' - 'Z'\n" );
78101 printf ("Must contain between %d and %d characters: " , S2LENGTHMIN , S2LENGTHMAX );
79102
80103 int numCharacters = 0 ; /* Keep track of num characters */
0 commit comments