Skip to main content
gamedev.net
🔒 Locked

Implement sscanf on stream...

Started by kimryo 2 replies 1k views
Original Post
kimryo
kimryo
Hi,I now need implement scanf on my stream interface,currently method is to first estimate the size format string may need,and read to a that sized buffer,then CRT sscanf...But...what a silly way... any good ways?Thx.
God create the world,we create another one.-Reference
Malchivus
Malchivus
i'm sorry if this is rude, but .. what?

are you talking about a home made scanf function? or do you want to perform scanf on an arbitrary stream?

if you do want the later, try using fscanf or setting stdin to your stream, scanf calls fscanf on the stream stdin.
I just wanna get this done.
kimryo
kimryo
Quote:
Original post by Malchivus
i'm sorry if this is rude, but .. what?

are you talking about a home made scanf function? or do you want to perform scanf on an arbitrary stream?

if you do want the later, try using fscanf or setting stdin to your stream, scanf calls fscanf on the stream stdin.


Yes, I want to implement a scanf on an arbitrary stream.
May the adapter from the arbitrary stream to CRT stream(stdin,stdout etc) is best way...
God create the world,we create another one.-Reference
Malchivus
Malchivus
hmm, if your trying to implement operations on a stream in the way that scanf does on stdin; you could use your own function and choose between data types (float, int etc) and then read byte by byte the data into the arguments.

if your using streams that behave like FILE* than fscanf WILL do all your work for you, the folowing macro explains how scanf and fscanf are related

#define scanf(...) fscanf( stdin, ... )

i hope its helpful, if you want a completely new stdargs function (...) then your goign to have to dig throught some source to find out how to use them ... i'd suggest "the c programing lanuguage" by kerigan and ritchie, but if you don't have a copy the internet should be able to give up the answer you want.

again, i hope i'm being helpful and not confusing ...
I just wanna get this done.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.