The nasty difference between fscanf and sscanf

Started by
3 comments, last by Riskbreaker 21 years, 1 month ago
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]
--RiskbreakerCoding Soul
Advertisement
Rather than trying to cram the entire buffer into sscanf at once, peel off smaller chunks and feed it those instead.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
String tokenizer! duh... thanks
--RiskbreakerCoding Soul
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?
E8 17 00 42 CE DC D2 DC E4 EA C4 40 CA DA C2 D8 CC 40 CA D0 E8 40E0 CA CA 96 5B B0 16 50 D7 D4 02 B2 02 86 E2 CD 21 58 48 79 F2 C3
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]

This topic is closed to new replies.

Advertisement