Reading file...

This is a discussion on Reading file... within the C Programming forums, part of the General Programming Boards category; I have a file that its content is like this: Code: MatName: "Mat1" { Ambient: 1 0 0 1 Diffuse: ...

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    132

    Reading file...

    I have a file that its content is like this:

    Code:
    MatName: "Mat1"
    {
    Ambient: 1 0 0 1
    Diffuse: 1 0 1 1
    }
    
    MatName: "Mat2"
    {
    Ambient: 1 0 1 1
    Diffuse: 0 0 0 1
    }
    for example. What I am trying to do is a function taht loads this file and takes a parameter MaterialName (f.e "Mat1", "Mat2", etc). How can I make the program to read only the block that the specified name is present?
    Y3K Network http://www.y3knetwork.com
    Bringing the software of the future on the net.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    pesudocode
    Object * fun1( const char * name )
    {
        read one object from file
        if( object name == name )
            return object
        else
            keep reading
    }
    That should get you started. Make one function that reads an entire "object" and returns it to this function. This function then compares it, and if found, returns that object. Otherwise, it keeps reading.

    Post your code, your errors, and where you're stuck.

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

  3. #3
    alkis_y3k
    Guest
    Ok I am using that already for something else so I get your point. Do you know any tutorial on fseek, sscanf, fscanf functtions?

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    There are plenty of sites that offer tutorials and example code. Have you tried searching these boards?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Registered User
    Join Date
    Jun 2002
    Posts
    132
    Will do. Thanks
    Y3K Network http://www.y3knetwork.com
    Bringing the software of the future on the net.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  2. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  3. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 09:46 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM

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