Scanf from data buffer in C/C?

You can use sscanf to scan memory blocks instead of files, similar to the way you can use sprintf to printf into memory. The prototype is.

You can use sscanf to scan memory blocks instead of files, similar to the way you can use sprintf to printf into memory. The prototype is: int sscanf (const char *str, const char *format, ...); In other words, the same as scanf but with a pointer added. That's for turning character data into other types.

If you have raw data in that memory buffer, you can cast and de-reference. In other words, say you have a memory buffer with an integer starting at the fifth location (offset 4), something like: #include int main(void) { // +--------------+--> little-endian, // | | 32-bit = 42. Char xyz = "1234\x2a\x00\x00\x00"; int x = *((int*)(xyz+4)); printf ("%d\n", x); return 0; } Assuming your integer encoding are the same as mine, this outputs 42 (hex 2A).

Taking that expression apart one bit at a time: (xyz+4) : Get the address four unit past xyz. Since xyz is a char pointer, this means four bytes. (int*)(xyz+4) : Cast it into an int pointer.

*((int*)(xyz+4)) : De-reference that to get the int at that address.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions