How can i detect just the new line input using scanf, and printing directory, like terminal
I wanna reproduce the terminal behavior when the input is just a new line (keeps printing the same string), but don't know how to do it.
Example: When the user just inputs a new line, the terminal keeps printing the directory, until a real command is inserted
int main()
{
char userInput[1024];
while (1)
{
printf("directory »» ");
scanf("%[^n]" , userInput); // This scanf doesn't work
while (userInput[0] == 'n') // If the input is only a new line char, keep asking for more inputs and printing the directory
{
printf("directory »» ");
scanf(" %[^n ]" , userInput); // This scanf doesn't work
}
//Input isn't a NewLine, process the input
process_Input_Function(userInput); //Isn't empty, search for my created commands
}
}
At the first enter
press, it enters the loop, reproduce 1 time, and then the scanf
doesn't detect new lines anymore, it just skips and waits to a real string.
What can i type inside of the scanf
to detect a new line input and keep printing that string till a real command is inserted?
I tried with scanf("%c"...)
but the problem with a char, is that i can't process the whole string command, if isn't empty
c
add a comment |
I wanna reproduce the terminal behavior when the input is just a new line (keeps printing the same string), but don't know how to do it.
Example: When the user just inputs a new line, the terminal keeps printing the directory, until a real command is inserted
int main()
{
char userInput[1024];
while (1)
{
printf("directory »» ");
scanf("%[^n]" , userInput); // This scanf doesn't work
while (userInput[0] == 'n') // If the input is only a new line char, keep asking for more inputs and printing the directory
{
printf("directory »» ");
scanf(" %[^n ]" , userInput); // This scanf doesn't work
}
//Input isn't a NewLine, process the input
process_Input_Function(userInput); //Isn't empty, search for my created commands
}
}
At the first enter
press, it enters the loop, reproduce 1 time, and then the scanf
doesn't detect new lines anymore, it just skips and waits to a real string.
What can i type inside of the scanf
to detect a new line input and keep printing that string till a real command is inserted?
I tried with scanf("%c"...)
but the problem with a char, is that i can't process the whole string command, if isn't empty
c
1
Try not to get in the habit of declaring comically tiny buffers. Use 1024 as a minimum, not 10. You could also do this withgetc
orread
.
– tadman
Nov 15 '18 at 16:24
3
consider not using scanf?
– Antti Haapala
Nov 15 '18 at 16:27
2
Code can not usescanf(“%s” …)
to read a line.
– chux
Nov 15 '18 at 17:20
1
Usingscanf()
string conversions (%s
or%
) without a field width (or assignment suppression with*
) is dangerous, because user-supplied input can overflow your buffer.
– Toby Speight
Nov 15 '18 at 17:37
add a comment |
I wanna reproduce the terminal behavior when the input is just a new line (keeps printing the same string), but don't know how to do it.
Example: When the user just inputs a new line, the terminal keeps printing the directory, until a real command is inserted
int main()
{
char userInput[1024];
while (1)
{
printf("directory »» ");
scanf("%[^n]" , userInput); // This scanf doesn't work
while (userInput[0] == 'n') // If the input is only a new line char, keep asking for more inputs and printing the directory
{
printf("directory »» ");
scanf(" %[^n ]" , userInput); // This scanf doesn't work
}
//Input isn't a NewLine, process the input
process_Input_Function(userInput); //Isn't empty, search for my created commands
}
}
At the first enter
press, it enters the loop, reproduce 1 time, and then the scanf
doesn't detect new lines anymore, it just skips and waits to a real string.
What can i type inside of the scanf
to detect a new line input and keep printing that string till a real command is inserted?
I tried with scanf("%c"...)
but the problem with a char, is that i can't process the whole string command, if isn't empty
c
I wanna reproduce the terminal behavior when the input is just a new line (keeps printing the same string), but don't know how to do it.
Example: When the user just inputs a new line, the terminal keeps printing the directory, until a real command is inserted
int main()
{
char userInput[1024];
while (1)
{
printf("directory »» ");
scanf("%[^n]" , userInput); // This scanf doesn't work
while (userInput[0] == 'n') // If the input is only a new line char, keep asking for more inputs and printing the directory
{
printf("directory »» ");
scanf(" %[^n ]" , userInput); // This scanf doesn't work
}
//Input isn't a NewLine, process the input
process_Input_Function(userInput); //Isn't empty, search for my created commands
}
}
At the first enter
press, it enters the loop, reproduce 1 time, and then the scanf
doesn't detect new lines anymore, it just skips and waits to a real string.
What can i type inside of the scanf
to detect a new line input and keep printing that string till a real command is inserted?
I tried with scanf("%c"...)
but the problem with a char, is that i can't process the whole string command, if isn't empty
c
c
edited Nov 15 '18 at 17:52
marcospb19
asked Nov 15 '18 at 16:24
marcospb19marcospb19
106
106
1
Try not to get in the habit of declaring comically tiny buffers. Use 1024 as a minimum, not 10. You could also do this withgetc
orread
.
– tadman
Nov 15 '18 at 16:24
3
consider not using scanf?
– Antti Haapala
Nov 15 '18 at 16:27
2
Code can not usescanf(“%s” …)
to read a line.
– chux
Nov 15 '18 at 17:20
1
Usingscanf()
string conversions (%s
or%
) without a field width (or assignment suppression with*
) is dangerous, because user-supplied input can overflow your buffer.
– Toby Speight
Nov 15 '18 at 17:37
add a comment |
1
Try not to get in the habit of declaring comically tiny buffers. Use 1024 as a minimum, not 10. You could also do this withgetc
orread
.
– tadman
Nov 15 '18 at 16:24
3
consider not using scanf?
– Antti Haapala
Nov 15 '18 at 16:27
2
Code can not usescanf(“%s” …)
to read a line.
– chux
Nov 15 '18 at 17:20
1
Usingscanf()
string conversions (%s
or%
) without a field width (or assignment suppression with*
) is dangerous, because user-supplied input can overflow your buffer.
– Toby Speight
Nov 15 '18 at 17:37
1
1
Try not to get in the habit of declaring comically tiny buffers. Use 1024 as a minimum, not 10. You could also do this with
getc
or read
.– tadman
Nov 15 '18 at 16:24
Try not to get in the habit of declaring comically tiny buffers. Use 1024 as a minimum, not 10. You could also do this with
getc
or read
.– tadman
Nov 15 '18 at 16:24
3
3
consider not using scanf?
– Antti Haapala
Nov 15 '18 at 16:27
consider not using scanf?
– Antti Haapala
Nov 15 '18 at 16:27
2
2
Code can not use
scanf(“%s” …)
to read a line.– chux
Nov 15 '18 at 17:20
Code can not use
scanf(“%s” …)
to read a line.– chux
Nov 15 '18 at 17:20
1
1
Using
scanf()
string conversions (%s
or %
) without a field width (or assignment suppression with *
) is dangerous, because user-supplied input can overflow your buffer.– Toby Speight
Nov 15 '18 at 17:37
Using
scanf()
string conversions (%s
or %
) without a field width (or assignment suppression with *
) is dangerous, because user-supplied input can overflow your buffer.– Toby Speight
Nov 15 '18 at 17:37
add a comment |
2 Answers
2
active
oldest
votes
Hmm, the code I gave pretty much does that with one exception, it doesn't display a prompt each time...
Is this what you mean:
#include <stdio.h>
#include <stdlib.h>
#include <string.h> // For the memset()
int main() {
char userInput[1024];
while (1) {
printf("»»» ");
fgets(userInput, 1024, stdin);
while (userInput[0] == 'n')
{
printf(">>> ");
memset(userInput, '', 1024);
fgets(userInput, 1024, stdin);
}
// Your command can be accessed from here //
printf("Command entered: %sn", userInput);
printf("Input isn't a NewLinen");
}
}
I changed the scanf()
to fgets()
to read from stdin
so that we don't overwrite the buffer.
add a comment |
First of all, your two scanf
calls are different. The first one is
scanf("%[^n]", userInput);
which looks for anything that's not a newline, as you wish to do.
But the second one is
scanf(" %[^n ]", userInput);
which is also looking for a space before the input, followed by any character that is also not a newline or a space. Thus, scanf is waiting for the space.
IMHO, the best way to recreate this behavior is going to be in the parsing step, after you have gotten the command from the command line. Essentially, your command input loop would look like this:
char *userInput = NULL;
size_t n = 0;
while (true) {
// print the prompt
printf(">");
// get the line
ssize_t userInputLength = getline(&userInput, &n, &stdin);
// parse the input, using a function you wrote elsewhere
parse(userInputLength, userInput);
}
(Note the use of POSIX getline()
instead of scanf
. This is a more recent standard library function that does exactly the task of getting a line of user input, and also allocates the buffer using malloc
and realloc
so that you don't have to care about buffer overflows or even sizing the buffer at all.)
The user input function wouldn't care that the userInput
portion was blank. The function that would care is the parse
function, which will simply interpret a blank userInput
string as "do nothing" and continue on its merry way.
Just try making it exactly like the first one. Does that work?
– TheHansinator
Nov 15 '18 at 16:34
No, it don't works, just starts an infinite loop
– marcospb19
Nov 15 '18 at 16:35
@marcospb19 OK, makes sense. I just added to my answer to suggest how you would actually pull this behavior off.
– TheHansinator
Nov 15 '18 at 16:44
I understood, but seems like this also created an infinite loop (the space behind usually stops that, but i don't figured a way to fix your code).
– marcospb19
Nov 15 '18 at 16:50
1
The 2nd"n"
inscanf("%[^n]n", userInput);
causesscanf()
to consume all whitespace include the'n'
and all other following WS until non-white-space if entered.
– chux
Nov 15 '18 at 17:38
|
show 3 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53323789%2fhow-can-i-detect-just-the-new-line-input-using-scanf-and-printing-directory-li%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Hmm, the code I gave pretty much does that with one exception, it doesn't display a prompt each time...
Is this what you mean:
#include <stdio.h>
#include <stdlib.h>
#include <string.h> // For the memset()
int main() {
char userInput[1024];
while (1) {
printf("»»» ");
fgets(userInput, 1024, stdin);
while (userInput[0] == 'n')
{
printf(">>> ");
memset(userInput, '', 1024);
fgets(userInput, 1024, stdin);
}
// Your command can be accessed from here //
printf("Command entered: %sn", userInput);
printf("Input isn't a NewLinen");
}
}
I changed the scanf()
to fgets()
to read from stdin
so that we don't overwrite the buffer.
add a comment |
Hmm, the code I gave pretty much does that with one exception, it doesn't display a prompt each time...
Is this what you mean:
#include <stdio.h>
#include <stdlib.h>
#include <string.h> // For the memset()
int main() {
char userInput[1024];
while (1) {
printf("»»» ");
fgets(userInput, 1024, stdin);
while (userInput[0] == 'n')
{
printf(">>> ");
memset(userInput, '', 1024);
fgets(userInput, 1024, stdin);
}
// Your command can be accessed from here //
printf("Command entered: %sn", userInput);
printf("Input isn't a NewLinen");
}
}
I changed the scanf()
to fgets()
to read from stdin
so that we don't overwrite the buffer.
add a comment |
Hmm, the code I gave pretty much does that with one exception, it doesn't display a prompt each time...
Is this what you mean:
#include <stdio.h>
#include <stdlib.h>
#include <string.h> // For the memset()
int main() {
char userInput[1024];
while (1) {
printf("»»» ");
fgets(userInput, 1024, stdin);
while (userInput[0] == 'n')
{
printf(">>> ");
memset(userInput, '', 1024);
fgets(userInput, 1024, stdin);
}
// Your command can be accessed from here //
printf("Command entered: %sn", userInput);
printf("Input isn't a NewLinen");
}
}
I changed the scanf()
to fgets()
to read from stdin
so that we don't overwrite the buffer.
Hmm, the code I gave pretty much does that with one exception, it doesn't display a prompt each time...
Is this what you mean:
#include <stdio.h>
#include <stdlib.h>
#include <string.h> // For the memset()
int main() {
char userInput[1024];
while (1) {
printf("»»» ");
fgets(userInput, 1024, stdin);
while (userInput[0] == 'n')
{
printf(">>> ");
memset(userInput, '', 1024);
fgets(userInput, 1024, stdin);
}
// Your command can be accessed from here //
printf("Command entered: %sn", userInput);
printf("Input isn't a NewLinen");
}
}
I changed the scanf()
to fgets()
to read from stdin
so that we don't overwrite the buffer.
edited Nov 15 '18 at 18:36
Jonathan Leffler
570k916831034
570k916831034
answered Nov 15 '18 at 16:45
NunchyNunchy
825411
825411
add a comment |
add a comment |
First of all, your two scanf
calls are different. The first one is
scanf("%[^n]", userInput);
which looks for anything that's not a newline, as you wish to do.
But the second one is
scanf(" %[^n ]", userInput);
which is also looking for a space before the input, followed by any character that is also not a newline or a space. Thus, scanf is waiting for the space.
IMHO, the best way to recreate this behavior is going to be in the parsing step, after you have gotten the command from the command line. Essentially, your command input loop would look like this:
char *userInput = NULL;
size_t n = 0;
while (true) {
// print the prompt
printf(">");
// get the line
ssize_t userInputLength = getline(&userInput, &n, &stdin);
// parse the input, using a function you wrote elsewhere
parse(userInputLength, userInput);
}
(Note the use of POSIX getline()
instead of scanf
. This is a more recent standard library function that does exactly the task of getting a line of user input, and also allocates the buffer using malloc
and realloc
so that you don't have to care about buffer overflows or even sizing the buffer at all.)
The user input function wouldn't care that the userInput
portion was blank. The function that would care is the parse
function, which will simply interpret a blank userInput
string as "do nothing" and continue on its merry way.
Just try making it exactly like the first one. Does that work?
– TheHansinator
Nov 15 '18 at 16:34
No, it don't works, just starts an infinite loop
– marcospb19
Nov 15 '18 at 16:35
@marcospb19 OK, makes sense. I just added to my answer to suggest how you would actually pull this behavior off.
– TheHansinator
Nov 15 '18 at 16:44
I understood, but seems like this also created an infinite loop (the space behind usually stops that, but i don't figured a way to fix your code).
– marcospb19
Nov 15 '18 at 16:50
1
The 2nd"n"
inscanf("%[^n]n", userInput);
causesscanf()
to consume all whitespace include the'n'
and all other following WS until non-white-space if entered.
– chux
Nov 15 '18 at 17:38
|
show 3 more comments
First of all, your two scanf
calls are different. The first one is
scanf("%[^n]", userInput);
which looks for anything that's not a newline, as you wish to do.
But the second one is
scanf(" %[^n ]", userInput);
which is also looking for a space before the input, followed by any character that is also not a newline or a space. Thus, scanf is waiting for the space.
IMHO, the best way to recreate this behavior is going to be in the parsing step, after you have gotten the command from the command line. Essentially, your command input loop would look like this:
char *userInput = NULL;
size_t n = 0;
while (true) {
// print the prompt
printf(">");
// get the line
ssize_t userInputLength = getline(&userInput, &n, &stdin);
// parse the input, using a function you wrote elsewhere
parse(userInputLength, userInput);
}
(Note the use of POSIX getline()
instead of scanf
. This is a more recent standard library function that does exactly the task of getting a line of user input, and also allocates the buffer using malloc
and realloc
so that you don't have to care about buffer overflows or even sizing the buffer at all.)
The user input function wouldn't care that the userInput
portion was blank. The function that would care is the parse
function, which will simply interpret a blank userInput
string as "do nothing" and continue on its merry way.
Just try making it exactly like the first one. Does that work?
– TheHansinator
Nov 15 '18 at 16:34
No, it don't works, just starts an infinite loop
– marcospb19
Nov 15 '18 at 16:35
@marcospb19 OK, makes sense. I just added to my answer to suggest how you would actually pull this behavior off.
– TheHansinator
Nov 15 '18 at 16:44
I understood, but seems like this also created an infinite loop (the space behind usually stops that, but i don't figured a way to fix your code).
– marcospb19
Nov 15 '18 at 16:50
1
The 2nd"n"
inscanf("%[^n]n", userInput);
causesscanf()
to consume all whitespace include the'n'
and all other following WS until non-white-space if entered.
– chux
Nov 15 '18 at 17:38
|
show 3 more comments
First of all, your two scanf
calls are different. The first one is
scanf("%[^n]", userInput);
which looks for anything that's not a newline, as you wish to do.
But the second one is
scanf(" %[^n ]", userInput);
which is also looking for a space before the input, followed by any character that is also not a newline or a space. Thus, scanf is waiting for the space.
IMHO, the best way to recreate this behavior is going to be in the parsing step, after you have gotten the command from the command line. Essentially, your command input loop would look like this:
char *userInput = NULL;
size_t n = 0;
while (true) {
// print the prompt
printf(">");
// get the line
ssize_t userInputLength = getline(&userInput, &n, &stdin);
// parse the input, using a function you wrote elsewhere
parse(userInputLength, userInput);
}
(Note the use of POSIX getline()
instead of scanf
. This is a more recent standard library function that does exactly the task of getting a line of user input, and also allocates the buffer using malloc
and realloc
so that you don't have to care about buffer overflows or even sizing the buffer at all.)
The user input function wouldn't care that the userInput
portion was blank. The function that would care is the parse
function, which will simply interpret a blank userInput
string as "do nothing" and continue on its merry way.
First of all, your two scanf
calls are different. The first one is
scanf("%[^n]", userInput);
which looks for anything that's not a newline, as you wish to do.
But the second one is
scanf(" %[^n ]", userInput);
which is also looking for a space before the input, followed by any character that is also not a newline or a space. Thus, scanf is waiting for the space.
IMHO, the best way to recreate this behavior is going to be in the parsing step, after you have gotten the command from the command line. Essentially, your command input loop would look like this:
char *userInput = NULL;
size_t n = 0;
while (true) {
// print the prompt
printf(">");
// get the line
ssize_t userInputLength = getline(&userInput, &n, &stdin);
// parse the input, using a function you wrote elsewhere
parse(userInputLength, userInput);
}
(Note the use of POSIX getline()
instead of scanf
. This is a more recent standard library function that does exactly the task of getting a line of user input, and also allocates the buffer using malloc
and realloc
so that you don't have to care about buffer overflows or even sizing the buffer at all.)
The user input function wouldn't care that the userInput
portion was blank. The function that would care is the parse
function, which will simply interpret a blank userInput
string as "do nothing" and continue on its merry way.
edited Nov 15 '18 at 19:20
Jonathan Leffler
570k916831034
570k916831034
answered Nov 15 '18 at 16:32
TheHansinatorTheHansinator
858725
858725
Just try making it exactly like the first one. Does that work?
– TheHansinator
Nov 15 '18 at 16:34
No, it don't works, just starts an infinite loop
– marcospb19
Nov 15 '18 at 16:35
@marcospb19 OK, makes sense. I just added to my answer to suggest how you would actually pull this behavior off.
– TheHansinator
Nov 15 '18 at 16:44
I understood, but seems like this also created an infinite loop (the space behind usually stops that, but i don't figured a way to fix your code).
– marcospb19
Nov 15 '18 at 16:50
1
The 2nd"n"
inscanf("%[^n]n", userInput);
causesscanf()
to consume all whitespace include the'n'
and all other following WS until non-white-space if entered.
– chux
Nov 15 '18 at 17:38
|
show 3 more comments
Just try making it exactly like the first one. Does that work?
– TheHansinator
Nov 15 '18 at 16:34
No, it don't works, just starts an infinite loop
– marcospb19
Nov 15 '18 at 16:35
@marcospb19 OK, makes sense. I just added to my answer to suggest how you would actually pull this behavior off.
– TheHansinator
Nov 15 '18 at 16:44
I understood, but seems like this also created an infinite loop (the space behind usually stops that, but i don't figured a way to fix your code).
– marcospb19
Nov 15 '18 at 16:50
1
The 2nd"n"
inscanf("%[^n]n", userInput);
causesscanf()
to consume all whitespace include the'n'
and all other following WS until non-white-space if entered.
– chux
Nov 15 '18 at 17:38
Just try making it exactly like the first one. Does that work?
– TheHansinator
Nov 15 '18 at 16:34
Just try making it exactly like the first one. Does that work?
– TheHansinator
Nov 15 '18 at 16:34
No, it don't works, just starts an infinite loop
– marcospb19
Nov 15 '18 at 16:35
No, it don't works, just starts an infinite loop
– marcospb19
Nov 15 '18 at 16:35
@marcospb19 OK, makes sense. I just added to my answer to suggest how you would actually pull this behavior off.
– TheHansinator
Nov 15 '18 at 16:44
@marcospb19 OK, makes sense. I just added to my answer to suggest how you would actually pull this behavior off.
– TheHansinator
Nov 15 '18 at 16:44
I understood, but seems like this also created an infinite loop (the space behind usually stops that, but i don't figured a way to fix your code).
– marcospb19
Nov 15 '18 at 16:50
I understood, but seems like this also created an infinite loop (the space behind usually stops that, but i don't figured a way to fix your code).
– marcospb19
Nov 15 '18 at 16:50
1
1
The 2nd
"n"
in scanf("%[^n]n", userInput);
causes scanf()
to consume all whitespace include the 'n'
and all other following WS until non-white-space if entered.– chux
Nov 15 '18 at 17:38
The 2nd
"n"
in scanf("%[^n]n", userInput);
causes scanf()
to consume all whitespace include the 'n'
and all other following WS until non-white-space if entered.– chux
Nov 15 '18 at 17:38
|
show 3 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53323789%2fhow-can-i-detect-just-the-new-line-input-using-scanf-and-printing-directory-li%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Try not to get in the habit of declaring comically tiny buffers. Use 1024 as a minimum, not 10. You could also do this with
getc
orread
.– tadman
Nov 15 '18 at 16:24
3
consider not using scanf?
– Antti Haapala
Nov 15 '18 at 16:27
2
Code can not use
scanf(“%s” …)
to read a line.– chux
Nov 15 '18 at 17:20
1
Using
scanf()
string conversions (%s
or%
) without a field width (or assignment suppression with*
) is dangerous, because user-supplied input can overflow your buffer.– Toby Speight
Nov 15 '18 at 17:37