问题
Is it possible to run scanf
on input that it is not STDIN? What I mean is if I have a string="hello 1 2 3"
, can I run scanf on it to extract the string and three integers?
Is there another function that can do this?
回答1:
sscanf
on a string (info here)
fscanf
on a file (info here)
similarly sprintf and fprintf to write to a string/file.
回答2:
If you have a string, sscanf would be more appropriate. The title of your question implies reading from a different stream, for which there are other similar functions (see fscanf).
来源:https://stackoverflow.com/questions/6922253/scanf-on-non-stdin-input