Thread: C Scrolling

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    104

    Lightbulb C Scrolling

    I'm suppose to make a prog that displays a bunch of stuff in table form, but the amount of colums is larger than the width of the screen, how do I put in a scroll bar or something like that so I can move left and right? (A vertical one might be nice too ) All of the table data is generated by a loop too btw, with the tables "headings" outside the loop and some info at the bottom.

  2. #2
    Registered User
    Join Date
    Jul 2003
    Posts
    61
    The closest thing I can think of right now is ncurses library on UNIX.

    HTH,
    $ENV: FreeBSD, gcc, emacs

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    char buf[BUFSIZ] = {0};
    char out[BUFSIZ] = {0};
    int xposition = 0;
    
    sprintf( buf, some_stuff, some_args );
    strncpy( out, buf+xposition, 78 );
    printf("%s\n", out );
    That'd work for a quick hack. Put it in a loop.

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164

    Re: C Scrolling

    Originally posted by Hexxx
    I'm suppose to make a prog that displays a bunch of stuff in table form, but the amount of colums is larger than the width of the screen, how do I put in a scroll bar or something like that so I can move left and right? (A vertical one might be nice too ) All of the table data is generated by a loop too btw, with the tables "headings" outside the loop and some info at the bottom.
    I think what you are really asking is how to increase the size of your window, which will automtically add scroll bars if it's larger than the screen. If so, which OS?
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  5. #5
    Registered User
    Join Date
    Oct 2003
    Posts
    104
    Well I just started coding, so I guess it for a console thingy or Dos\Windows.

  6. #6
    Registered User
    Join Date
    Oct 2003
    Posts
    104
    Did I mention that I only started Comp Sci a couple weeks ago? I don't get most of how to even start to do what you're taking about. Maybe posting the code might help make it easier.
    Code:
    #include <stdio.h>
    #include <conio.h>
    void main () {
    	FILE *indata=fopen("c:\\cs10e\\input3.txt", "r");
    	FILE *outdata=fopen("C:\\cs10e\\output3.txt", "w");
    	
    	int lines=0, prt_num, prc_brk_quant, quant_sold, peakprt=9999, peaksale=0;
    	float init_amt, unit_prc, brk_discount, grand_discount, post_brk_discount, net_pay, total_discount;
    	
    	clrscr();
    	if (indata==NULL) {
    		printf ("No data file found!");
    		getch();
    		exit();
    		          }
    	fscanf (indata,"%d", &prt_num);
    	printf ("===============================================================================\n");
    	printf ("Part_No. Unit_Price Price_Break_Quant Quant_Sold Initial_Amt Discount   Net_Pay\n");
    	printf ("===============================================================================\n");
    	fprintf (outdata,"===============================================================================\n");
    	fprintf (outdata,"Part_No. Unit_Price Price_Break_Quant Quant_Sold Initial_Amt Discount   Net_Pay\n");
    	fprintf (outdata,"===============================================================================\n");
    	while (prt_num!=9999) {
    			fscanf (indata,"%f", &unit_prc);
    			fscanf (indata,"%d", &prc_brk_quant);
    			fscanf (indata,"%d", &quant_sold);
    		
    			if (quant_sold>peaksale) {
    				peakprt=prt_num;
    				peaksale=quant_sold;}
    			init_amt=unit_prc*quant_sold;
    			
    			if (quant_sold>=prc_brk_quant) {
    				brk_discount=0.1*init_amt;
    				post_brk_discount=init_amt-brk_discount; }
    			else {
    				brk_discount=0.00;
    				post_brk_discount=init_amt-brk_discount; }
    
    			if (post_brk_discount>1000.00) {
    				grand_discount=.05*post_brk_discount;
    				net_pay=post_brk_discount-grand_discount;}
    			else {
    				grand_discount=0.00;
    				net_pay=post_brk_discount-grand_discount;}
    		
    		total_discount=brk_discount+grand_discount;
    		fprintf (outdata,"%7d %11.2f %17d %10d %9.2f %9.2f %10.2f\n",prt_num, unit_prc, prc_brk_quant, quant_sold, init_amt, total_discount, net_pay );
    		printf ("%7d %11.2f %17d %10d %9.2f %9.2f %10.2f\n",prt_num, unit_prc, prc_brk_quant, quant_sold, init_amt, total_discount, net_pay );
    		lines++;
    		fscanf (indata,"%d", &prt_num);	}
    	printf ("-------------------------------------------------------------------------------\n\n");
    	printf ("Total number of data lines = %d\n", lines);
    	printf ("The highest quantity sold is Part No. %d, with %d sells\n", peakprt, peaksale);
    	fprintf (outdata,"-------------------------------------------------------------------------------\n\n");
    	fprintf (outdata,"Total number of data lines = %d\n", lines);
    	fprintf (outdata,"The highest quantity sold is Part No. %d, with %d sells\n", peakprt, peaksale);
    	fclose(indata);
    	fclose(outdata);
    	}
    It's suppose to read some data (4 numbers) from a file for each "part" and list them and do some basic calculations, but I think I might have to add another column and there isn't space on the screen.
    The data is suppose to be four numbers and stop reading when there is a fake part no. called 9999
    Example data file>>

    45 78 54 65
    1 2 3 6
    9999

  7. #7
    Registered User
    Join Date
    Oct 2003
    Posts
    104
    anyone?

  8. #8
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Don't bump your threads, read the forum Guidelines .

    >> I guess it for a console thingy or Dos\Windows.
    At your current level of programming, you don't have control over the window environment you're running in. Windows Consoles are hard to work with when it comes to resizing and smaller fonts etc.

    My advise is to change the output your program produces to make it fit the current screen size.

    >>void main ()
    http://faq.cprogramming.com/cgi-bin/...&id=1043284376
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  9. #9
    Registered User
    Join Date
    Oct 2003
    Posts
    1
    Not sure if this is exactly what you are looking for but try these libaries

    curses.h (linux), conio.h(windows)
    Last edited by Aiursrage2k; 10-13-2003 at 03:01 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Scrolling background?
    By Deo in forum Game Programming
    Replies: 6
    Last Post: 06-09-2005, 05:40 PM
  2. Scrolling
    By PJYelton in forum Windows Programming
    Replies: 10
    Last Post: 03-24-2003, 10:04 AM
  3. Bitmap scrolling with scroll bars
    By solar3147 in forum Windows Programming
    Replies: 0
    Last Post: 03-17-2003, 02:39 AM
  4. SkyLock graphics demo (scrolling, etc.)
    By jdinger in forum Game Programming
    Replies: 9
    Last Post: 06-30-2002, 08:18 PM
  5. Vesa. Parallax scrolling.
    By r0x in forum Game Programming
    Replies: 5
    Last Post: 06-10-2002, 05:39 PM