Hey, I have another problem...

I am using a FOR loop which is making a lot of lines.
The problem is that the new lines "runs over" the first lines because there is no room for the new ones.

In shortly, when a new line comes and have no room, the toppest line disappears and so the new line comes.

I need a way to cancel this line "limit", a friend told me the answer is probably a function that changes the console propeties but I don't really know how to find it (although I tried).

Please help, Thanks =]

Recommended Answers

All 14 Replies

If it's for the screen, you should add some line of like this, inside your for loop:

for(i = 0; i < SomeBigNumber; i++) {
   if(i < 20)
      your print line of code goes here
}

That will let the only the first 20 lines of code be printed.

Changing the console properties isn't the answer - the console can't accommodate a lot of lines, no matter what you do. If you try, you'll only make the text char's so small you can't read them without a magnifying glass. :)

If it's for the screen, you should add some line of like this, inside your for loop:

for(i = 0; i < SomeBigNumber; i++) {
   if(i < 20)
      your print line of code goes here
}

That will let the only the first 20 lines of code be printed.

Yes, but I need all of the lines printed and all of them appearing

Have you tried writing the text to a file instead of just to the screen? Then when you need to retrieve it, you'll have everything saved in your file.

If that's not the answer, maybe a different compiler would work better?

Dev-C++ wouldn't scroll for me when I used Vista, but on Windows 7 it does. So maybe a different compiler would allow scroll bars so you can see all your text.

Have you tried writing the text to a file instead of just to the screen? Then when you need to retrieve it, you'll have everything saved in your file.

If that's not the answer, maybe a different compiler would work better?

Dev-C++ wouldn't scroll for me when I used Vista, but on Windows 7 it does. So maybe a different compiler would allow scroll bars so you can see all your text.

About the text file, I don't really know because all of the text is made from a FOR loop. I don't know if and how you can do it in a text file.

And I tried Visual C++, and Dev C++ and the problem wasn't was scrolling.. I could scroll, but the toppest line isn't the first.

Could you show your code? Maybe the problem is in the for loop itself, but it's hard to know that for sure without seeing the code.

I think now I can tell you more...
I found out that if you right click the blue bar of the border at the top of the program's window, you have propeties and there's history for the lines... I need a code that increases them.

I know you might not want to accept this, but there ARE limits to what your console window can show.

What about having your program pause displaying more lines after X number have been printed? Then, when you hit <enter> key, the next page of lines would be printed up.

I use that, a lot, and it works well. The mod operator is key:

if(++lines % 20 (whatever number you like) == 0) {
  getchar();
}

Put that right inside your busy loop, and edit out the "whatever number you like" bit, and try that.

Every line of output has a newline either at the beginning or the end of the print statement, right?

I think now I can tell you more...
I found out that if you right click the blue bar of the border at the top of the program's window, you have propeties and there's history for the lines... I need a code that increases them.

Will SetConsoleScreenBufferSize help?

Will SetConsoleScreenBufferSize help?

Don't know that function and it doesn't recognize it also.
Could you please tell me what to include and how to use?

Hmm.. I am very sorry but I can't understand this.
I've been in this page but I seem to can't undesrtand Microsoft's help..

I guess it's too complicated for me. sorry...

If your code is not interactive, again piping the output to a file seems like the easiest. For example,

D:\projects\misc\c>Debug\capp.exe > file.txt

If your code is not interactive, again piping the output to a file seems like the easiest. For example,

D:\projects\misc\c>Debug\capp.exe > file.txt

Yeah, that helps, but I still want to know for my next programs, what to do if the text IS interactive...

Yeah, that helps, but I still want to know for my next programs, what to do if the text IS interactive...

You can try to resort to the SetConsoleScreenBufferSize() function, as suggested by nezachem. It is actually quite simple, so maybe try running the below code and see how it works.

#include <stdio.h>
#include <windows.h>

int main(int argc, char *argv[])
{
  /* Initialize the screen buffer info to zero */
  CONSOLE_SCREEN_BUFFER_INFO info = {0};

  /* You need the console's std output handle */
  HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);

  if(hStdOut == INVALID_HANDLE_VALUE)
  {
    /* No luck */
    printf("GetStdHandle() failed, error: %lu\n", GetLastError());
    return 0;
  }

  /* Get the current settings ... */
  if( ! GetConsoleScreenBufferInfo(hStdOut, &info))
  {
    /* No luck */
    printf("GetConsoleScreenBufferInfo() failed, error: %lu\n",
        GetLastError());
    return 0;
  }

  /* Adjust this to your likings, info.dwSize.Y is a SHORT, 
   * so, keep within the limits of a SHORT.
   * SHRT_MAX is defined in <limits.h>
   */
  info.dwSize.Y = SHRT_MAX - 1;

  /* Interestingly, seems that SHRT_MAX - 1 is the maximum
   * working value instead of SHRT_MAX.
   */

  /* Apply your new settings ... */
  if( ! SetConsoleScreenBufferSize(hStdOut, info.dwSize))
  {
    /* No luck */
    printf("SetConsoleScreenBufferSize() failed, error: %lu\n",
        GetLastError());
    return 0;    
  }

  /* Print lines up to the maximum, once finished,
   * you should still be able to see the first line printed.
   */
  for(int ii = 0; ii < info.dwSize.Y; ++ii)
  {
    printf("\nline# %d", ii);
  }

  getchar();

  return 0;
}

If you want to increase the number of characters that fit into a single line, then increase the value of info.dwSize.X .

Documentation for CONSOLE_SCREEN_BUFFER_INFO Structure, it provides links to other related functions etc.

PS. The screen buffer changes impact only the running console i.e. it does not do any system-wide changes to the console configuration.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.