Problem with awk awk: program limit exceeded: sprintf buffer size=1020

Hi

I have many problems with a script. I have a script that formats a text file but always prints the same error when i try to execute it

The code is that:

{
      if (NF==17){
            print $0
      }else{
            fields=NF;
            all=$0;
            while (fields<17){
                  getline;
                  todo=sprintf("%s %s",all,$0);
                  campos=fields + NF;
                  fields=campos;
                  all=todo;
            }
            print all;
      }
}

i execute it:

awk -F '@@@' -f kk.awk productos.TXT
awk: program limit exceeded: sprintf buffer size=1020
FILENAME="productos.TXT" FNR=2 NR=2

How could I make the buffer not to get full?

thanks

Can you plz share with us what exactly are you trying to do. May be we can then help you.

If you only keep in a buffer the data, why not use printf for write directly

{
      if (NF==17){
            print $0
      }else{
            fields=NF;
            printf("%s", $0)
            while (fields<17){
                  getline;
                  printf("%s", $0)
                  campos=fields + NF;
                  fields=campos;
            }
            printf "\n"
      }
}

But I still don't understand some partes in the script, why do you use fields and campos variables? Is correct to print a line with less than 17 fields and another with exactly 17 fields in the same line?