Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ea650c7

Browse files
Update logic in the main function to preserve a copy of the original randomly generated array of characters
1 parent 3f63d2c commit ea650c7

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed

‎Source.c‎

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,28 @@ char getReplacementCharacter();
1212
void strfilter(char s1[S1LENGTH + 1], char s2[S2LENGTHMAX + 1], char ch);
1313

1414
int isUpperCaseLetter(int iochar);
15-
void duplicateArray(char s1[S1LENGTH + 1], char s3[S1LENGTH + 1]);
15+
void duplicateArray(char original[S1LENGTH + 1], char copy[S1LENGTH + 1]);
1616

1717
int main(void) {
1818
printf("Welcome User\n");
1919
char selection = 'Y';
2020
int invalidSelectionFlag;
2121

22+
/* Generate a random pattern of uppercase letters only once */
23+
char original[S1LENGTH + 1];
24+
generateS1(original);
25+
2226
while (selection == 'Y' || selection == 'y') {
2327
/* Reset invalidSelectionFlag */
2428
invalidSelectionFlag = 0;
2529

26-
/* Generate a random pattern of uppercase letters */
30+
/* Generate a copy of the randomly generated array, called s1 */
2731
char s1[S1LENGTH + 1];
28-
generateS1(s1);
32+
duplicateArray(original, s1);
2933

3034
/* Get user string of uppercase letters */
3135
char s2[S2LENGTHMAX];
32-
36+
3337
do {
3438
generateS2(s2); /* Loop until we have a valid string */
3539
} while (s2[0] == '0円');
@@ -40,10 +44,6 @@ int main(void) {
4044
do {
4145
ch = getReplacementCharacter(); /* Loop until we have a single valid character */
4246
} while (ch == '0円');
43-
44-
/* Before we modify s1, we'll create a copy of s1 called original */
45-
char original[S1LENGTH + 1];
46-
duplicateArray(s1, original);
4747

4848
/* Search s1 and replaces any occurrences of any of the characters contained in s2 with character ch */
4949
strfilter(s1, s2, ch);
@@ -210,32 +210,26 @@ int isUpperCaseLetter(int iochar) {
210210
}
211211

212212
/* Copies values from s1 into s2 */
213-
void duplicateArray(char s1[S1LENGTH + 1], char s3[S1LENGTH + 1]) {
213+
void duplicateArray(char original[S1LENGTH + 1], char copy[S1LENGTH + 1]) {
214214
for (int i = 0; i < S1LENGTH + 1; ++i) {
215-
s3[i] = s1[i];
215+
copy[i] = original[i];
216216
}
217217
}
218218

219-
/* TEST CASE */
219+
/* TEST CASES */
220220
/*
221-
222221
1. User enters single lowercase char
223222
2. User enters single uppercase char
224223
3. User enters all uppercase chars, exceeds max limit (>20)
225-
4. User enters mix of upper/lowercase chars, exceeds max limit
226-
5. User enters mix of upper/lowercase chars, within limit (2-20)
227-
228-
6. Replacement char is more than one char
229-
230-
7. User enters string when prompted to repeat program
231-
8. User enters invalid single char when prompted to repeat program
232-
9. User enters lowercase 'y' to repeat program
233-
234-
235-
236-
237-
238-
224+
4. User enters all lowercase chars, exceeds max limit
225+
5. User enters mix of upper/lowercase chars, exceeds max limit
226+
6. User enters mix of upper/lowercase chars, within limit (2-20)
227+
7. User enters non-alphabetical characters
228+
8. User enters max possible characters
239229
230+
9. Replacement char is more than one chararacter long
240231
232+
10. User enters string when prompted to repeat program
233+
11. User enters invalid single char when prompted to repeat program
234+
12. User enters lowercase 'y' to repeat program
241235
*/

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /