Posted May 2, 20178 yr 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
May 2, 20178 yr 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); }
May 2, 20178 yr Author Hi, thanks for your answer but I need some usable (assembly / API etc) example. So is it possible to translate this part anyhow? greetz
May 2, 20178 yr 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, 20178 yr by evlncrn8
May 2, 20178 yr @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
May 2, 20178 yr 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!
May 2, 20178 yr Author 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
Create an account or sign in to comment