LCF-AT Posted May 2, 2017 Posted May 2, 2017 Hi again, does anyone know any function/s to split a text file (any text of notepad etc) into single lines by CRLF? Example: I have simple textfile which has 10 lines (each line with return at the end / CRLF) and now I read the file into buffer via ReadFile API and now I got the whole text in buffer and now I need to check manually for CRLF at the end or not if not present etc.So is there any simple function/s etc I could use to get a entire line by line back?Maybe there is anything I could use and dont know yet. Thank you
Kurapica Posted May 2, 2017 Posted May 2, 2017 In C++ I use "getline" //Open the text file ifstream file; file.open("C:\\sequence.txt"); if (!file.is_open()) { printf("error while opening file\n"); system("Pause"); return 1; } //Read the file line by line string line; for(int i = 0; i < 1000; i++) { getline(file,line); } 1
LCF-AT Posted May 2, 2017 Author Posted May 2, 2017 Hi, thanks for your answer but I need some usable (assembly / API etc) example. So is it possible to translate this part anyhow? greetz
evlncrn8 Posted May 2, 2017 Posted May 2, 2017 (edited) its hardly rocket science, readline is just a high level abstract -> https://dev.w3.org/libwww/Library/src/vms/getline.c make buffer -> read buffer size bytes from file -> process until \r \n or \0, if no ending is found, reallocate the buffer 2x the size, loop, repeat ad nauseaum... there's no 'magic' win api to do it and to save the i/o overhead and memory allocation and reallocation, depending on the size, it might just be best to memory map the bloody thing also bear in mind for linux the 0d 0a is the other way round...and then of course, exotic files..utf-8 and so on.. joy Edited May 2, 2017 by evlncrn8 2
Kurapica Posted May 2, 2017 Posted May 2, 2017 @LCF-AT I thought you were coding with C++ you can find several working assembly snippets, for example this looks like what you need : http://stackoverflow.com/questions/33639379/x86-asm-read-line-by-line 2
CodeExplorer Posted May 2, 2017 Posted May 2, 2017 read_mode db "r",0 ReadConfigInfo proc invoke crt_fopen, ADDR FILE, ADDR read_mode .if eax==0 ; when fails is zero ret .endif mov hfile1,eaxinvoke crt_fgets,ADDR buffer2, sizeof buffer2, hfile1 https://msdn.microsoft.com/en-us/library/c37dh6kf(v=vs.71).aspx Separated by newline! Hope it helps! 2
LCF-AT Posted May 2, 2017 Author Posted May 2, 2017 Hi again guys, thanks for the infos and also thanks for the API example CodeCracker. So thats good so far with that msvcrt API. So now I dont need to handle that manually as I did before. greetz
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now