Printing 20 lines at a time
I am completing a group project and I just found out that I need to print just 20 lines at a time. I have added the code I thought I needed to add, but it wouldnt work correctly. I know this is easy and I should know how to do it, but I am just having trouble thinking through the process logically. I need to add code to the following piece of code to print only 20 lines at a time.
for (j = 0; j < i; j++)
{
for(k = 0; k < 4; k++)
printf("\t%10d", CustAry[j][k]);
printf("\n");
}
Re: Printing 20 lines at a time
Quote:
Originally posted by csmatheng
Code:
for (j = 0; j < i; j++)
{
for(k = 0; k < 4; k++)
printf("\t%10d", CustAry[j][k]);
printf("\n");
}
what is i set to? You should just be able to set it to 20 to print the first 20 elements of the array. But you must check that there are actually 20 or more elements, or you'll prog will fail.
Also, for clarity, try writing your code with the braces after the inner for loop. It makes it easier to read, especially when you're starting out:
Code:
for (j = 0; j < i; j++)
{
for(k = 0; k < 4; k++)
{
printf("\t%10d", CustAry[j][k]);
}
printf("\n");
}
Hammer (i is set to # of customers)
Hammer, " i " is set to the number of customers so I cannot use it to control the loop. I just need to add to the code I posted, so that it will only print 20 lines at a time. Thanks for your help and interest.
Re: Hammer (i is set to # of customers)
Quote:
Originally posted by csmatheng
I just need to add to the code I posted, so that it will only print 20 lines at a time.
Then it looks like swoopy's code (or a variant of) will do what you want, depending on what you want to do when you get to 20 lines (pause, stop etc).
If you want to stop at 20, another way to do so is to just change your original for statement a little:
Code:
for (j = 0; j < i && j < 20; j++)
{
for(k = 0; k < 4; k++)
{
printf("\t%10d", CustAry[j][k]);
}
printf("\n");
}