text file

This is a discussion on text file within the C Programming forums, part of the General Programming Boards category; Hi, I am writing a program that asks the user to input a file name and the program then reads ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    10

    text file

    Hi,
    I am writing a program that asks the user to input a file name and the program then reads what is in the file and sends that information to another function. I am a little confused on how to begin. I know the file will contain a string followed by two numbers, but I don't know how many strings there will be.
    Like I said I really don't know how to start. Any suggustions would be great.

    thanks

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    start here
    Code:
    #include <stdio.h>
    
    int main()
    {
       // your code goes here
    
      return 0;
    }
    you will need a character array of about 255 characers (to hold the longest possible filename) then call fgets() to get the file name from the keyboard. After that, call fopen() to open the file, fgets() to read each line, and finally fclose() to close the file.

    Code:
    display prompt to enter filename
    get filename from keyboard (use fgets() function)
    open the file
    start of loop
       call fgets() to read one line from the file
       if fgets() returns NULL then exit the loop
       call some other function with line as parameter
    end of loop
    close file

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  2. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 01:59 PM
  3. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM
  4. checking values in a text file
    By darfader in forum C Programming
    Replies: 2
    Last Post: 09-24-2003, 02:13 AM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 02:58 PM

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