C++ getline long input problem

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

syzygy
Posts: 5563
Joined: Tue Feb 28, 2012 11:56 pm

Re: C++ getline long input problem

Post by syzygy »

phhnguyen wrote: Sat Jun 02, 2018 5:05 pm Oops, are you sure you are giving suggestions for lazy-lack-skill people like me? :shock:

Creating one more program and / or programming with pipe techniques obviously is not easy and quick tasks.

The above solution requires me to copy / paste only few code lines. I have added already some defines to turn it on/off when need.
It should be obvious by now that you are creating your own problems by insisting on copy and pasting directly into the terminal.

If you are able to convert an engine from xboard to UCI, you should certainly be able to write a trivial program that prints a string of a given length to the terminal.

Code: Select all

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
  int num = argc > 1 ? atoi(argv[1]) : 100;

  for (int i = 0; i < num; i++)
    printf("a");

  return 0;
}

Code: Select all

$ gcc program.c -o program
$ ./program 12
aaaaaaaaaaaa$ ./program 123456 | wc -c
123456
$ ./program 123456 | ./getlinetest
str length: 123456
Copying and pasting a 10000 character string directly indeed bumps into a tty-induced limit of 4095.
User avatar
phhnguyen
Posts: 1434
Joined: Wed Apr 21, 2010 4:58 am
Location: Australia
Full name: Nguyen Hong Pham

Re: C++ getline long input problem

Post by phhnguyen »

You missed my purpose. All I need is to debug my engine and the long string is actually a position with a lot of moves (it is not a test with some fix-known strings). Copy and paste that long string into my program's stream is much easier, faster and debug-able.

If I have to change code and re-compile a program, I may add that string directly into my program. Easier?
https://banksiagui.com
The most features chess GUI, based on opensource Banksia - the chess tournament manager
syzygy
Posts: 5563
Joined: Tue Feb 28, 2012 11:56 pm

Re: C++ getline long input problem

Post by syzygy »

phhnguyen wrote: Sat Jun 02, 2018 5:39 pm You missed my purpose. All I need is to debug my engine and the long string is actually a position with a lot of moves (it is not a test with some fix-known strings). Copy and paste that long string into my program's stream is much easier, faster and debug-able.

If I have to change code and re-compile a program, I may add that string directly into my program. Easier?
How can I miss something that you never told us? (First you say it is too difficult for you, now you say it does not serve a never-stated purpose...)

You opened a thread about C++ getline() not accepting long strings, which if true would obviously break your UCI engine. We have now established that there is in fact nothing wrong with C++ getline().

If you want to test a particular position (and you need the game history so a simple FEN does not suffice), then you could paste the UCI commands to a text file and redirect stdin.
User avatar
phhnguyen
Posts: 1434
Joined: Wed Apr 21, 2010 4:58 am
Location: Australia
Full name: Nguyen Hong Pham

Re: C++ getline long input problem

Post by phhnguyen »

syzygy wrote: Sat Jun 02, 2018 6:04 pm How can I miss something that you never told us? (First you say it is too difficult for you, now you say it does not serve a never-stated purpose...)
You right!
syzygy wrote: Sat Jun 02, 2018 6:04 pm You opened a thread about C++ getline() not accepting long strings, which if true would obviously break your UCI engine. We have now established that there is in fact nothing wrong with C++ getline().

If you want to test a particular position (and you need the game history so a simple FEN does not suffice), then you could paste the UCI commands to a text file and redirect stdin.
The main problem I have no skills nor experience to work with UCI and I did not know it was wrong because of getline or not. The discussing is giving me some working experience actually.

BTW don't take anything serious. I am learning from you all and highly appreciate all ideas and suggestions.
Have a great weekend!
https://banksiagui.com
The most features chess GUI, based on opensource Banksia - the chess tournament manager