Thread: reading files and displaying them on screen

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    30

    reading files and displaying them on screen

    Hi,

    How do you read a text file and display it on screen. Its just a text file NEW.TXT. Does anyone have an example? or can tell me how to do it?

    thanks

    Kendals

  2. #2
    Registered User
    Join Date
    Aug 2001
    Location
    computers/ theatre, travelingstudentL>- Northern California NativeNorthern California3D&Tie-DyeStudent1>. Admirer of C Bangalore Net surfingTeacher >/ >0 nagpurteaching >1  >2
    Posts
    61
    char tempStr[128];
    FILE *fPtr = fopen("NEW.TXT", "r");

    while(!feof(fPtr)) {
    fgets(tempStr, 80, fPtr);
    fprintf(stderr,"%s\n", tempStr);
    }

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    30

    how do i go next and back

    Hi,

    Once i have loaded my text file how do i go next and back to view the next records and previous records?
    do you have an example of this using an array?

    thanks

    Kendals

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    30

    your code doesnt work properly

    Hi,

    I tried your code and i cannot get it to read the whole txt file.
    Your code only reads the first line?
    Can you help?

    thanks

    kendals

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Are you just trying to dump the entire contents to the screen?
    Code:
    FILE *fp = fopen( "myfile.txt", "r" );
    int c;
    while ( (c=fgetc(fp)) != EOF ) printf("%c", c );
    You really should read up on the f* functions and learn a bit more on how they work.

    Additionally, you may want to use psesudo code to explain your problem first:
    Code:
    while we're not at the end of the file
        read a line
        put the line on the screen
    As per above, if you used a loop with the previous poster's code, you'd have your answer already.

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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Displaying files in a particular path in listbox????
    By richa.malhotra in forum Windows Programming
    Replies: 1
    Last Post: 02-28-2008, 07:11 PM
  2. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  3. ascii characters video displaying on tv screen
    By deian in forum C Programming
    Replies: 6
    Last Post: 10-12-2004, 09:46 PM
  4. Displaying all the files of a folder
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 04-17-2002, 12:49 PM
  5. displaying text files, wierd thing :(
    By Gades in forum C Programming
    Replies: 2
    Last Post: 11-20-2001, 05:18 PM