flat assembler
Message board for the users of flat assembler.
Index
> Windows > C's malloc |
Author |
|
revolution 19 Mar 2010, 15:45
Quote: char * fgets ( char * str, int num, FILE * stream ); |
|||
19 Mar 2010, 15:45 |
|
sandman_1 19 Mar 2010, 16:03
Thanks for your reply but could you elaborate more?
I know how to use fgets and it should return the same address to where it wrote to on success, which it does per check Ollydbg. Am I overlooking something? |
|||
19 Mar 2010, 16:03 |
|
revolution 19 Mar 2010, 16:08
Quote: ... until (num-1) characters have been read or either a newline or a the End-of-File is reached ... |
|||
19 Mar 2010, 16:08 |
|
sandman_1 19 Mar 2010, 20:12
Thanks for pointing that out. It makes sense now why it doesn't work. When the program is ran, the output shows the cursor a couple of lines below where it should be like there are a couple of returns and then a linefeed. Anyway, I will check it out.
|
|||
19 Mar 2010, 20:12 |
|
sandman_1 20 Mar 2010, 00:20
Ok got it to work with fgetc.
Code: mov esi, [memalloc] write_char: cinvoke fgetc, [fileopen] cmp eax, -1 je done mov byte [esi], al inc esi jmp write_char done: mov byte [esi], 0 I am still baffled about the whole file still being printed in memory with the old code. It as if fgets loaded the whole file in a buffer for some reason and then worked on it, weird. Anyone want to add anything like a better way to do this besides using fgetc and a loop? Suggestions? |
|||
20 Mar 2010, 00:20 |
|
revolution 20 Mar 2010, 00:34
sandman_1 wrote: I am still baffled about the whole file still being printed in memory with the old code. It as if fgets loaded the whole file in a buffer for some reason and then worked on it, weird. In general, you should not be accessing buffers from other code unless you like to get all sorts of strange errors and/or crashes when msvcrt.dll next changes. It is also not guaranteed that the memory block msvcrt.dll allocates will always be directly after your block, don't rely on such behaviour. sandman_1 wrote: Anyone want to add anything like a better way to do this besides using fgetc and a loop? Suggestions? Quote: size_t fread ( void * ptr, size_t size, size_t count, FILE * stream ); |
|||
20 Mar 2010, 00:34 |
|
sandman_1 20 Mar 2010, 02:38
Thanks for the info. I will heed your advice.
Good idea! I will try using that instead in my code, thank you. |
|||
20 Mar 2010, 02:38 |
|
sandman_1 20 Mar 2010, 15:55
Fread worked like a charm but the setup code to use it is about the same as the loop I made. But there is only one function call so it is more efficient compared to several fgetc's. Thanks again for your suggestion...
|
|||
20 Mar 2010, 15:55 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.