Archived

This topic is now archived and is closed to further replies.

Riskbreaker

The nasty difference between fscanf and sscanf

Recommended Posts

I have this huge buffer (size of an uncompressed image file), and I've had two scenarios so far: 1. Reading in the file off disk into memory using fscanf. Works great, since each successive read of fscanf increments the file pointer. 2. Reading in the file from a raw memory space using sscanf (it was downloaded internally via FTP)... Doesn't work, because apparently, sscanf has no way of returning a pointer to where it last scanned... so it starts at the beginning of the buffer for each successive scan. Can anyone think of a way to get a pointer of where sscanf last scanned? Is there another function that can do this? It's awfully tough to manually calculate it, since the data scanned in is not in char form. Maybe there's a way to get my app to *think* it's a file stream, so I can use fscanf? Thanks for any suggestions! [edited by - Riskbreaker on March 7, 2003 3:12:18 PM]

Share this post


Link to post
Share on other sites
quote:
Doesn''t work, because apparently, sscanf has no way of returning a pointer to where it last scanned... so it starts at the beginning of the buffer for each successive scan.
Can anyone think of a way to get a pointer of where sscanf last scanned?

RTFM (looking for %n)

> huge buffer (size of an uncompressed image file)
> It''s awfully tough to manually calculate it, since the data scanned in is not in char form.
> String tokenizer!
What exactly are you reading?

Share this post


Link to post
Share on other sites
It sounds like unformatted data, and if it is you should be using neither fscanf nor sscanf, which are for formatted data.

What exactly is the data like (formatted, unformatted, etc.)? It's possible to grab it all at once if you really want, just have to use the right tools

[edited by - Zipster on March 7, 2003 6:19:37 PM]

Share this post


Link to post
Share on other sites