Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mad
concierge
Commits
29786349
Commit
29786349
authored
Jun 10, 2014
by
Oliver Feldt
Browse files
nitpicking and better c standard compliant code
parent
e315738b
Changes
1
Hide whitespace changes
Inline
Side-by-side
challenge/challenge.c
View file @
29786349
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
int
main
()
{
int
ret
;
size_t
nbytes
=
0
;
char
*
input_str
=
NULL
;
char
*
password
=
"23door42
\n
"
;
const
char
*
password
=
"23door42
\n
"
;
int
main
(
void
)
{
size_t
input_size
=
0
;
char
*
input_line
=
NULL
;
printf
(
"Please enter Password: "
);
ret
=
getline
(
&
input_str
,
&
nbytes
,
stdin
);
if
(
ret
==
-
1
)
{
puts
(
"Error"
);
}
else
if
(
strcmp
(
input_str
,
password
)
==
0
)
{
puts
(
"Success"
);
ret
=
0
;
// read in password from standard input, exit on error.
if
(
getline
(
&
input_line
,
&
input_size
,
stdin
)
==
-
1
)
{
perror
(
"Error"
);
exit
(
EXIT_FAILURE
);
}
// compare password, print info, exit appropriately
if
(
strcmp
(
input_line
,
password
)
==
0
)
{
puts
(
"Success!"
);
exit
(
EXIT_SUCCESS
);
}
else
{
puts
(
"How about no?!"
);
ret
=
-
1
;
exit
(
EXIT_FAILURE
)
;
}
free
(
input_str
);
return
ret
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment