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
Lucia Štefanková
notwork
Commits
b68d24fa
Commit
b68d24fa
authored
Mar 19, 2020
by
Sergej Chodarev
Browse files
Remove use of nonstandard getline function
parent
1f904eff
Changes
2
Hide whitespace changes
Inline
Side-by-side
Makefile
View file @
b68d24fa
CC
=
gcc
CFLAGS
=
-std
=
gnu
11
-Wall
-pedantic
CFLAGS
=
-std
=
c
11
-Wall
-pedantic
-g
LDFLAGS
=
TARGET
=
notwork
...
...
notwork.c
View file @
b68d24fa
#include
<ctype.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<string.h>
#include
"wall.h"
void
empty_input_buffer
()
{
...
...
@@ -19,20 +20,23 @@ void show_wall_ui(wall_t *wall) {
}
void
write_post_ui
(
wall_t
*
wall
)
{
char
*
text
=
NULL
;
size_t
length
=
0
;
int
read
;
char
text
[
MAX_POST_LENGTH
+
2
];
// leave space for newline and 0
size_t
newline_pos
=
0
;
printf
(
"Enter your post:
\n
"
);
read
=
getline
(
&
text
,
&
length
,
stdin
);
text
[
read
-
1
]
=
'\0'
;
// remove the trailing newline
post_t
*
post
=
create_post
(
text
);
free
(
text
);
if
(
post
!=
NULL
)
{
add_post
(
wall
,
post
);
}
else
{
printf
(
"Try to fit your post into %d characters."
,
MAX_POST_LENGTH
);
fgets
(
text
,
MAX_POST_LENGTH
+
2
,
stdin
);
newline_pos
=
strcspn
(
text
,
"
\n
"
);
if
(
newline_pos
<=
MAX_POST_LENGTH
)
{
text
[
newline_pos
]
=
'\0'
;
// remove the trailing newline
}
else
{
// Newline not found, so input must be longer then the limit
printf
(
"Post longer then %d characters. It would be truncated.
\n
"
,
MAX_POST_LENGTH
);
text
[
MAX_POST_LENGTH
]
=
0
;
empty_input_buffer
();
}
post_t
*
post
=
create_post
(
text
);
add_post
(
wall
,
post
);
}
post_t
*
select_post_ui
(
wall_t
*
wall
,
char
*
question
)
{
...
...
Write
Preview
Supports
Markdown
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