Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

How to read a text line by line / CRLF?

Featured Replies

Posted

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

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);
	}

 

  • 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

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 by evlncrn8

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,eax
invoke  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!

 

  • 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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.