Thread: need help.....again

  1. #1
    cereal killer dP munky's Avatar
    Join Date
    Nov 2002
    Posts
    655

    need help.....again

    im wanting to read from a file...now, maybe im misunderstanding how reading from a file works...but i when i read in from my text file, the last line isnt showing up?...like the last line in the text file.

    heres the info in the text file..
    Assume that someone is typing his final report for english class
    into a text file. After completing the report, he realized that
    he mistakenly had the caps lock key on throughout the typing process. He said
    oh my gosh what have i done? How am i going to fix this? Blah Blah Blah.

    Code:
    #include <stdio.h>
    
    int main()
    {
    	char sentence[1024];
    	FILE *rptPTR;   /* file pointer to the report*/
    
    	if (( rptPTR = fopen("report.txt", "r+") ) == NULL )
    	{
    		printf("File could not be opened!\n");
    	}
    
    	else 
    	{
    		fgets(sentence, 1024, rptPTR);
    
    		while( !feof(rptPTR))
    		{
    			printf("%s", sentence);
    			fgets(sentence, 1024, rptPTR);
    		}
    	
    		fclose(rptPTR);
    	}
    
    
    	return 0;
    }
    windows xp using MSVC 6
    Last edited by dP munky; 11-22-2002 at 01:21 AM.
    guns dont kill people, abortion clinics kill people.

  2. #2
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Try this:
    Code:
    while(fgets(sentence, 1024, rptPTR) != NULL)
    {
    	printf("%s", sentence);
    }

  3. #3
    cereal killer dP munky's Avatar
    Join Date
    Nov 2002
    Posts
    655
    LMAO, now its not grabbing the first line
    guns dont kill people, abortion clinics kill people.

  4. #4
    cereal killer dP munky's Avatar
    Join Date
    Nov 2002
    Posts
    655
    nevermind....i got it...thanks for the help man mucho apreciato'
    guns dont kill people, abortion clinics kill people.

Popular pages Recent additions subscribe to a feed