Dear all,

I am learning C language.

I got the following problem while running the problem.

Program:

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

main()
{
int x;
for (x = 1; x <= 250; x ++)
printf("x = %d\n", x);
}

OUTOUT should be:
x = 1
x = 2
x = 3
x = 4
|
|
|
|
|
x = 249
x = 250
After running the program, i get the true output also, but all 250 lines are not printed in the output. There are only 50 Lines are printed in the output.

Means I get the output as below.

OUTPUT:
x = 201
x = 202
x = 203
x = 204
|
|
|
|
|
x = 249
x = 250

Then, where the lines above 200 gone...?
Can anybody help me to check "How can i see the entire output (Black screen -Dos)?

Thanks and Regards,
Nakul Pancholi

Edited 6 Years Ago by WaltP: Added CODE tags -- with all the help about them, how could you miss using them????

You can use the function getchar() to pause for the user to hit a key. You can use an if statement with the modulus (%) operator to set how many lines you want before the user is prompted.

For example 0 % 50 = 0, 50 % 50 = 0, 100 % 50 = 0.
See if you can come up with it.

P.S. To see where your prior output has gone you can scroll back in the cmd window. If you are using windows you can set the scrollback buffer by going to the system menu (upper left hand corner) of the cmd window, Properties, Layout tab, Screen Buffer Size and adjust the height.

Edited 6 Years Ago by jonsca: n/a

You can use the function getchar() to pause for the user to hit a key. You can use an if statement with the modulus (%) operator to set how many lines you want before the user is prompted.

For example 0 % 50 = 0, 50 % 50 = 0, 100 % 50 = 0.
See if you can come up with it.

Dear Friend,

i am getting the right output. But when output is very long, the above lines of output (in black screen - Dos) are lapsed. In turbo C, we can not print more than 50 lines. Kindly help me for this situation.
Thanks and regards,

You can use the function getchar() to pause for the user to hit a key. You can use an if statement with the modulus (%) operator to set how many lines you want before the user is prompted.

For example 0 % 50 = 0, 50 % 50 = 0, 100 % 50 = 0.
See if you can come up with it.

P.S. To see where your prior output has gone you can scroll back in the cmd window. If you are using windows you can set the scrollback buffer by going to the system menu (upper left hand corner) of the cmd window, Properties, Layout tab, Screen Buffer Size and adjust the height.

Thank you very much dear friend..Let me check. If i will get any problem then definitely contact you.

Hi Nakul,

Try to learn C the right way:

1) It's always int main(), never just main() or void main(), and it always has a return integer (generally always 0).

2) now let's make your program look like a *program* on the forum:

Just click on the [.code] icon, in the advanced edit window (I added a period so it would show what it looks like).

Note: code tags, int main(), return 0, a getchar to hold the console window from closing too fast, AND good 3 space indentation. All add up to a better program and programmer.

The indentation allows programmers to use their experienced eye to spot trouble, much more quickly. You will be doing that, as well, before long.

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

int main()
{
   int x;
   for (x = 1; x <= 250; x ++)
      printf("x = %d\n", x);

   printf("\n\t\t\t     press enter when ready");
   getchar();  //holds the console window open, if needed
   return 0;
}

Try this version of your program, and see if the problem still exists.

Edited 6 Years Ago by Adak: n/a

Yeah give it a try. This will let you pause the screen. That way everything won't go flying by. Run your exe at a prompt to get a more accurate picture as I'm not sure (and I'm sure not gonna find out) what goes on when you run it in the shell of TC.

P.S. Also learn to use code tags. Very simple

[code]

/*code goes here*/ /*more code*/

[/code]

Dear Friend,
I am still getting the same problem.
Suppose we are running the program, in which the output is more than 50 lines, how can we put break or pause in the program.?
And also, Suppose i i print
1
2
3
.
.
.
52
using program then even after scrolling the window and go to the top, the scrollbar vanishes and the output will start from 3.
That is,
3
4
5
.
.
.
.
48
49
50

Can you please explain it to me..?

Thank you very much,
Nakul Pancholi

Hi Nakul,

Try to learn C the right way:

1) It's always int main(), never just main() or void main(), and it always has a return integer (generally always 0).

2) now let's make your program look like a *program* on the forum:

Just click on the [.code] icon, in the advanced edit window (I added a period so it would show what it looks like).

Note: code tags, int main(), return 0, a getchar to hold the console window from closing too fast, AND good 3 space indentation. All add up to a better program and programmer.

The indentation allows programmers to use their experienced eye to spot trouble, much more quickly. You will be doing that, as well, before long.

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

int main()
{
   int x;
   for (x = 1; x <= 250; x ++)
      printf("x = %d\n", x);

   printf("\n\t\t\t     press enter when ready");
   getchar();  //holds the console window open, if needed
   return 0;
}

Try this version of your program, and see if the problem still exists.

Dear Friend Adak,

Still i am getting the same problem.

Kindly go through following.
Dear Tenax,

My friend, Suppose we are running the program, in which the output is more than 50 lines, how can we put break or pause in the program.?
And also, Suppose i i print
1
2
3
.
.
.
52
using program then even after scrolling the window and go to the top, the scrollbar vanishes and the output will start from 3.
That is,
3
4
5
.
.
.
.
48
49
50

Can you please explain it to me..?

Thank you very much,
Nakul Pancholi

how can we put break or pause in the program.?

See post #2.

I don't know why your system is doing that? Are you running it within the "shell" of Turbo C or are you running it at a dos prompt? Beyond that I don't know. Is your instructor that bent on how your output appears on his screen? I'm certain he understands there are not 250 lines.

See post #2.

I don't know why your system is doing that? Are you running it within the "shell" of Turbo C or are you running it at a dos prompt? Beyond that I don't know. Is your instructor that bent on how your output appears on his screen? I'm certain he understands there are not 250 lines.

Dear Friend,

But are you getting my point or not? As i want to see entire output on my screen. How it will be possible, that i want to know. Even if with DOS prompt i am getting same thing.

Can anybody help..?

Thanks and regards

I'm getting your point but unless you have a 250 line display you're not going to see it all at once. I don't believe there is any standard method for reducing the text size. That's why I was offering you the technique to pause the output every 50 lines (even for that you'd have to stretch the window from an "average" cmd prompt).

I don't believe there is any standard method for reducing the text size.

This is the crux of the problem. You cannot view more than 50 lines at a time in DOS mode (as far as i know). But there is a trick. It involves pausing the screen after every 50 outputs. The algorithm is something like this

FOR LOOP ( START = 1 | END : WHEN START =  250 | INCREMENT START )
{    
    PRINT (VALUE OF START)
    IF (START IS A MULTIPLE OF 50)
    {
        PAUSE
    }
}

Convert this to code and i think you'll do fine ...

Or try this but I'm not sure whether this will work or not
Go to cmd, right click, properties -> options tab -> buffer size. Set it to 250. Set it for future use. Then try to run your program. Let me know of the results

Dear Friend,

But are you getting my point or not? As i want to see entire output on my screen. How it will be possible, that i want to know. Even if with DOS prompt i am getting same thing.

Can anybody help..?

Thanks and regards

Get a new monitor that has 255 lines on it.

Or remove the \n from the printf() line.

Dear Friends,
I got it..We can set it to cmd. By clicking the cmd property, we can set the maximum number of lines up to 9999.
This is for your information.

Thank you very much for your kind support.

Thanks and Regards,
Nakul

You might wanna mark this thread as solved...

How? Can you please explain dear friend..?

Scroll down towards the bottom of the page until you hit the Tags section (in green) move one line up from that (next to the gold "Reply to this thread" button). It says Mark as Solved.

xavier there's no reason to jump on a thread you hadn't posted on before just to say that.

Edited 6 Years Ago by jonsca: n/a

If the output in the turboc runtime screen is very large means,the cursor is at the end of output.which key is pressed to go at the intial stage of output

This question has already been answered. Start a new discussion instead.