Thread: Reading a specific line from a text file

  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, 07: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, 07:13 PM
  5. Validating the contents of a char buffer
    By mattz in forum C Programming
    Replies: 3
    Last Post: 12-09-2001, 06:21 PM