0

I have seen here that is possible to get the length of all output to the console at a given time, however I am wanting to get the length of an individual line in the console (i.e. at a specific COORD). Is this possible with Win32 API?

Swordfish
  • 12,971
  • 3
  • 21
  • 43
  • "I have seen here that is possible to get the length of all output to the console at a given time" um. no. The code in the answer you linked to does not do that. – Swordfish Sep 24 '18 at 06:48
  • @Swordfish Ahh so `dwSize.X` is the max(?) width of the console buffer? – wizardstack Sep 24 '18 at 07:07
  • @Swordfish If that is the case I could use that. My problem is that I am trying to delete lines from the console, however sometimes it overlaps onto the next line and clears that too – wizardstack Sep 24 '18 at 07:08
  • @Yes, `GetConsoleScreenBufferInfo` gives you the width. – Swordfish Sep 24 '18 at 07:12

1 Answers1

1

Use GetConsoleScreenBufferInfo() to get the width of the console screen buffer. Next do for every position from width to 0 in the line you are interested in ReadConsoleOutput() and check if the character at the position is a whitespace character (isspace()). If it is not you have found the position of the last character in the line and its X-coordinate is the lenght of the line.

Swordfish
  • 12,971
  • 3
  • 21
  • 43