Reading a specific line from a text file

This is a discussion on Reading a specific line from a text file within the C Programming forums, part of the General Programming Boards category; Hello, I need to read a specific line from a text file. Per example what do i have to do ...

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    2

    Reading a specific line from a text file

    Hello, I need to read a specific line from a text file. Per example what do i have to do to read the 4th line from a random *.txt file? I thought about counting "\n" 3 times and then scanning the file until getting to another "\n" or the end of the file (if this is the last line) but i don't really have the skills to do it

    Acid

  2. #2
    Registered User
    Join Date
    Nov 2009
    Posts
    60
    Which skills you don't have? Opening a file? Reading a line? ....?

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Do you know how to make a loop? Loop three times, ignoring what you read. Or you could just read 1 character at a time and check for newlines. Either way. You could of course just use fgets.


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

  4. #4
    Registered User
    Join Date
    Dec 2009
    Posts
    2
    Quote Originally Posted by quzah View Post
    Do you know how to make a loop? Loop three times, ignoring what you read. Or you could just read 1 character at a time and check for newlines. Either way. You could of course just use fgets.


    Quzah.
    Yes i do. Ill try to do it now thanks.

    Quote Originally Posted by hilarius View Post
    Which skills you don't have? Opening a file? Reading a line? ....?
    What i meant to say is that I'm new to C programming, (а noob...)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading a file line by line
    By Raskalnikov in forum C Programming
    Replies: 8
    Last Post: 03-18-2009, 11:44 PM
  2. Replies: 7
    Last Post: 02-02-2009, 06:27 AM
  3. Reading output into a text file
    By pete212 in forum C Programming
    Replies: 8
    Last Post: 04-23-2008, 05:11 PM
  4. reading from text file
    By jamez in forum C Programming
    Replies: 3
    Last Post: 11-30-2005, 06:13 PM
  5. Validating the contents of a char buffer
    By mattz in forum C Programming
    Replies: 3
    Last Post: 12-09-2001, 05:21 PM

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