Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
assignment_2
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
esp-ws20
assignment_2
Commits
008a2371
Commit
008a2371
authored
4 years ago
by
Franza, Simone
Browse files
Options
Downloads
Patches
Plain Diff
clear buffer after wrong input
parent
7c221c24
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
framework.c
+14
-2
14 additions, 2 deletions
framework.c
framework.h
+8
-0
8 additions, 0 deletions
framework.h
with
22 additions
and
2 deletions
framework.c
+
14
−
2
View file @
008a2371
...
...
@@ -16,6 +16,7 @@ void generatePlayfairSquare(char *square)
printf
(
"%s "
,
KEY_PROMPT
);
fgets
(
key
,
SIZE_BUFFER
,
stdin
);
if
(
checkStringValidity
(
key
,
MAX_KEY_LENGTH
,
IS_KEY
))
break
;
clearBuffer
(
key
,
SIZE_BUFFER
);
}
prepareKey
(
key
);
...
...
@@ -121,7 +122,8 @@ void appendAlphaToKey(char *key)
{
char
alpha
[
SQUARE_SIDE
*
SQUARE_SIDE
+
1
]
=
ALPHA
;
int
length
=
stringLength
(
key
);
for
(
int
counter
=
0
;
counter
<
SQUARE_SIDE
*
SQUARE_SIDE
+
1
;
counter
++
)
{
for
(
int
counter
=
0
;
counter
<
SQUARE_SIDE
*
SQUARE_SIDE
+
1
;
counter
++
)
{
if
(
stringContainsChar
(
key
,
alpha
[
counter
])
==
NOT_FOUND
)
*
(
key
+
length
++
)
=
alpha
[
counter
];
}
...
...
@@ -129,9 +131,19 @@ void appendAlphaToKey(char *key)
}
//-----------------------------------------------------------------------------
int
stringContainsChar
(
char
*
text
,
char
to_find
)
{
int
stringContainsChar
(
char
*
text
,
char
to_find
)
{
do
{
if
(
*
text
==
to_find
)
return
FOUND
;
}
while
(
*
text
++
);
return
NOT_FOUND
;
}
//-----------------------------------------------------------------------------
void
clearBuffer
(
char
*
text
,
int
buffer_len
)
{
for
(
int
counter
=
0
;
counter
<
buffer_len
;
counter
++
)
{
text
[
counter
]
=
'\0'
;
}
}
This diff is collapsed.
Click to expand it.
framework.h
+
8
−
0
View file @
008a2371
...
...
@@ -131,3 +131,11 @@ void appendAlphaToKey(char *key);
// @return FOUND(1) or NOT_FOUND(-1)
//
int
stringContainsChar
(
char
*
text
,
char
to_find
);
//-----------------------------------------------------------------------------
// Zeroes the content of a string
//
// @param text string to clear
// @param buffer_len length of string
//
void
clearBuffer
(
char
*
text
,
int
buffer_len
);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment