Thread: Reading a text file

  1. #46
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Where did the file come from? Did you get the file from your instructor? Did some other program write the file? It really doesn't matter as long as the file remains consistent. This is part of the problems with dealing with user/file input, you must know how the file is laid out in order to process it correctly. Sometimes this involves trial and error, after making an educated guess.

    Jim

  2. #47
    C Beginner
    Join Date
    Dec 2011
    Location
    Portugal
    Posts
    187
    Quote Originally Posted by jimblumberg View Post
    Where did the file come from? Did you get the file from your instructor? Did some other program write the file? It really doesn't matter as long as the file remains consistent. This is part of the problems with dealing with user/file input, you must know how the file is laid out in order to process it correctly. Sometimes this involves trial and error, after making an educated guess.

    Jim
    My instructor gave me whole work on a pdf, I took it of the pdf and pasted it on my Text Editor on Ubuntu.

    Dean.

  3. #48
    C Beginner
    Join Date
    Dec 2011
    Location
    Portugal
    Posts
    187
    About the rest of the code, you adviced me to use strcmp to check if the %s we got from the sscanf is a NODE,GRAPH or EDGE, correct ?

    Imagine that %s is NODE :
    Code:
    if (strcmp(Tipo,"NODE"))
    From the line in which NODE is I can get the first vertex and it's condition but I can't get his heir since his heir is on the EDGE one.
    How to fix this ?

    Thanks, Dean.

  4. #49
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    I don't understand your question. Does each EDGE line correspond to a particular NODE?

    Jim

  5. #50
    C Beginner
    Join Date
    Dec 2011
    Location
    Portugal
    Posts
    187
    Quote Originally Posted by jimblumberg View Post
    I don't understand your question. Does each EDGE line correspond to a particular NODE?

    Jim
    Kinda.
    Each NODE has a vertex with his condition and each vertex is connected with another vertex (that is shown on the EDGES).
    For example if we have EDGE 1 5 it means that the vertex 1 is connected with the vertex 5 or in this case that the vertex 5 is vertex 1's heir.

  6. #51
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    So in the following line: NODE 2 := x1 -x0, is the vertex 2? What is the significance of the :=, x1, -x0?

    Jim

  7. #52
    C Beginner
    Join Date
    Dec 2011
    Location
    Portugal
    Posts
    187
    Quote Originally Posted by jimblumberg View Post
    So in the following line: NODE 2 := x1 -x0, is the vertex 2? What is the significance of the :=, x1, -x0?

    Jim
    Yeah, in that case we're working with vertex 2.
    := x1 -x0 would be the condition and looking at your .txt vertex 3 would be vertex 2 heir.

  8. #53
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    It seems to me that you will need some kind of data structure to hold this information. Since you read a text file sequentially you must save the information for later processing. What these structures entail will depend on how the data will be used after you read your file. At the very least you will need a couple of arrays to hold the data points.

    Jim

  9. #54
    C Beginner
    Join Date
    Dec 2011
    Location
    Portugal
    Posts
    187
    Hmm, so basically I'll have to make a data structure that will have a field for NODES, a field for GRAPH and a field for EDGES and that as it reads the fields, it saves the information on the specific fields.
    That's what you mean right ?

    Dean.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 05-05-2010, 02:43 PM
  2. Reading from a text file
    By chevyman2002 in forum C Programming
    Replies: 10
    Last Post: 03-09-2009, 04:40 PM
  3. Reading in a text file.
    By killpoppop in forum C Programming
    Replies: 6
    Last Post: 01-11-2009, 04:38 PM
  4. Reading a text file
    By AmazingRando in forum C Programming
    Replies: 2
    Last Post: 09-08-2003, 10:38 AM
  5. Reading from a text file.
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 05-08-2002, 07:02 PM