I need a simple function that can read multiple words into a string in C, kind of like Scanner.nextLine()
in Java or Console.ReadLine()
in C#, but I can't seem to find a simple method anywhere, I tried all sorts of things, but none of them seem to work 100% of the time.
相关问题
- Multiple sockets for clients to connect to
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- Index of single bit in long integer (in C) [duplic
- Equivalent of std::pair in C
This removes the '\n' character that is included in the string returned by fgets, thus making the function practically equivalent to the functions present in popular managed languages:
scanf
is what you want:You can use fgets
Be aware that fgets reads until reach the size n, or a newline or an EOF. This is made to avoid buffer overflow, so you need to make sure that your buffer is big enough to store the string.
you can follow this:
Here you go:
Use fgets to parse an input string into a char buffer.
Here is the link for a better description
Then use sscanf to dissect this string to however you need it.
Here is the link for a better description