gave it shot...it gave me an error!

This is a discussion on gave it shot...it gave me an error! within the C Programming forums, part of the General Programming Boards category; Hi there...I need to incorporate pagination in my program which produces over a 500 records...each record is about 4 lines ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    6

    gave it shot...it gave me an error!

    Hi there...I need to incorporate pagination in my program which produces over a 500 records...each record is about 4 lines approx. 4-5 fit on the screen...i am not certain abt how to do this but i gave this a shot:

    Code:
     /* 
    
    while(!feof(fp))
    {
    	while(fgets(line,300,fp)!=NULL)
    	{
    		chk++;
    		funk(line, fp);
    		x=ftell(fp);
    		fseek(fp,x,0);
    		if(chk==5)
    		{
    			printf("Press 'N' for next set of records\n\n OR\n\n'X' to Quit");
    			getchar();
    			scanf(" %c",&ans1);
    			if(ans1=='N')
    			{
    				continue;
    				chk=0;
    			}
    			else
    				exit();
    		}
    	}
    }
     */
    since i know the number of records that'd fit on the screen, I take a counter (chk=0) and increment everytime the function that prints one record is called...as soon as chk==5, i ask the user to print N for the next 5 records and set chk back to 0...doesn't work!

    any suggestions will be greatly appreciated...cheers!

  2. #2
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    1.) Dont' use feof() and fgets() together, it's not right. Search the forums to know why.
    2.) Have you initialised 'chk'?
    3.) You don't need these. When you call fgets(), after reading the number of bytes requested or the max possible, fgets() automatically sets the file pointer to the next byte in stream. You don't need to do it explicitly.
    >x=ftell(fp);
    >fseek(fp,x,0);
    4.) You don't need these either:
    >getchar();
    >scanf(" %c",&ans1);
    You just either of them, not both. And if you are using getchar(), makesure:
    ans1 = getchar();
    5.) It's always a good habit to close all open files and do the clean up job before quitting, though exit() mihgt do it for you automatically.
    >else
    > exit();

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    6
    thanx for ur advice buddy...put all your concerns to rest since the code posted here is part of a much larger program...so all ur concerns abt initialising chk and closing files are taken care of

    i pasted just this part since it contains the logic for pagination...i'd appreciate suggestions pertaining to that...cheers!

  4. #4
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    >thanx for ur advice buddy
    Welcome.

    >put all your concerns to rest since the code posted here is part of a much larger program
    If you think you don't need them, you put them to rest, because there are many more here who would have learnt something from this.

    >so all ur concerns abt initialising chk and closing files are taken care of
    Great.

    >i pasted just this part since it contains the logic for pagination...i'd appreciate suggestions pertaining to that...cheers!
    Logic looks good, lacks implementation though. To learn how, refer my above post.

    And yes, cheers!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 03:09 AM
  3. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 03:35 PM
  4. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21