Thread: fgets trouble

  1. #1
    Registered User
    Join Date
    Sep 2009

    fgets trouble

    Hi all!

    I'm trying to use fgets to read a .txt file. My problem is that the text that i want to be read is in parenthesis. What command should I use to tell fgets to start reading from "(" and stop reading when ")" occurs?

    I'm a newbie and I have no idea how to solve this.

    Thanks in advance for help

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    segmentation fault
    You can't.

    If the parenthesized text spans multiple lines, read the whole file into an array first. If not, you can just work line by line. Either way, you read data in with fgets and then you have a little function which uses strchr() to extract what you want.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Sep 2009
    Great! Thanks a lot!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. trouble with fgets() !
    By davewang in forum C Programming
    Replies: 13
    Last Post: 11-25-2008, 03:13 PM
  2. problem with fgets
    By learninC in forum C Programming
    Replies: 3
    Last Post: 05-19-2005, 08:10 AM
  3. problem with fgets
    By Smoot in forum C Programming
    Replies: 4
    Last Post: 12-07-2003, 03:35 AM
  4. fgets crashing my program
    By EvBladeRunnervE in forum C++ Programming
    Replies: 7
    Last Post: 08-11-2003, 12:08 PM
  5. help with fgets
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 10-17-2001, 08:18 PM