| |

VerySource

 Forgot password?
 Register
Search
View: 3197|Reply: 23

scanf weird

[Copy link]

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-2-1 11:20:01
| Show all posts |Read mode
A very weird thing happened with scanf today, it didn't wait for input from the terminal and returned 0 directly; and started executing the next statement. Wang experts ask
Reply

Use magic Report

0

Threads

55

Posts

44.00

Credits

Newbie

Rank: 1

Credits
44.00

 Invalid IP Address

Post time: 2020-3-13 07:30:01
| Show all posts
Post code
Reply

Use magic Report

0

Threads

63

Posts

43.00

Credits

Newbie

Rank: 1

Credits
43.00

 China

Post time: 2020-3-14 00:00:01
| Show all posts
Is it like\n left in the input stream?
Reply

Use magic Report

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-3-14 01:30:01
| Show all posts
printf ("Please Select Test:");
int result = scanf ("% d",&choice);

The reason is related to calling a function in a dynamic link library, but as for what is related, you can't see the original program of dll.
Reply

Use magic Report

0

Threads

11

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 Invalid IP Address

Post time: 2020-3-14 10:00:01
| Show all posts
fgets until '\n'.
Reply

Use magic Report

0

Threads

55

Posts

44.00

Credits

Newbie

Rank: 1

Credits
44.00

 Invalid IP Address

Post time: 2020-3-14 16:30:01
| Show all posts
Use fflush (stdin); to clear the input buffer.
Reply

Use magic Report

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-3-14 21:00:02
| Show all posts
fflush (stdin);

Plus this is OK, thanks!
Reply

Use magic Report

0

Threads

63

Posts

43.00

Credits

Newbie

Rank: 1

Credits
43.00

 China

Post time: 2020-3-16 14:00:01
| Show all posts
int result = scanf ("% * 1d% d",&choice); // Skip 1 character
Reply

Use magic Report

0

Threads

63

Posts

43.00

Credits

Newbie

Rank: 1

Credits
43.00

 China

Post time: 2020-3-16 16:45:01
| Show all posts
fflush (stdin); Obviously undefined behavior, why do so many people like to use nirvana?
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-16 19:15:01
| Show all posts
No empty buffer
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list