fscanf issue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • momotaro
    Contributor
    • Sep 2006
    • 357

    fscanf issue

    is it correct to write that:
    [CODE=c]

    fscanf(InputFil e, "%s %d %d", NewVertex->CarId, NewVertex->x, NewVertex->y);

    [/CODE]
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by momotaro
    is it correct to write that:
    [CODE=c]

    fscanf(InputFil e, "%s %d %d", NewVertex->CarId, NewVertex->x, NewVertex->y);

    [/CODE]
    The *scanf family of functions need an address to store their scanned and converted
    values to, so if your expressions result in an char*, int* and an int* everything is fine.

    kind regards,

    Jos

    Comment

    • momotaro
      Contributor
      • Sep 2006
      • 357

      #3
      hence i dont no where is the problem in those lines of code:
      [CODE=c] for(i = 0; i < vehicules; i++)

      {

      NewVertex = CreatVertex();

      // up to here ok

      fscanf(InputFil e, "%s %d %d", NewVertex->CarId, NewVertex->x, NewVertex->y);

      }

      [/CODE]

      this is the file:
      5

      250

      Toto 25 50

      Foo 20 50

      X 50 100

      Y -100 -200

      Z -5 150

      the program cruch

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        What is the type of 'NewVertex->x'? If it is an int* you're fine; otherwise you'd
        better pass the address of that variable to your *scanf() function. The same
        reasoning applies to your NewVertex->y variable.

        kind regards,

        Jos

        Comment

        • momotaro
          Contributor
          • Sep 2006
          • 357

          #5
          am trying to impliment a linked list to hold a graph (2D linked list col for vertices and rows for edges...)
          is this structer correct?

          [CODE=c] typedef struct _list list;

          struct _list
          {
          edge *E;
          vertex *V;
          list *NextVertex,
          *NextEdge;
          } ;
          [/CODE]

          Comment

          • momotaro
            Contributor
            • Sep 2006
            • 357

            #6
            or:

            [CODE=c] typedef struct _edge edge;
            typedef struct _vertex vertex;
            typedef struct _edgelist edgelist;
            typedef struct _vertexlist vertexlist;

            struct _edge
            {
            CarID[10];
            int distance;
            };

            struct _vertex
            {
            CarID[10];
            int x,
            y;
            };

            struct edgelist
            {
            edge *E;
            edgelist *next;
            };

            struct edgevertex
            {
            vertex *V;
            vertexlist *next;
            };
            [/CODE]

            if you have any better implimentation please help!

            Comment

            • momotaro
              Contributor
              • Sep 2006
              • 357

              #7
              originaly am using these structers to impliment my graph:

              [CODE=c] typedef struct _edge edge;

              typedef struct _vertex vertex;



              struct _edge

              {

              char CarId[10];

              int distance;

              edge *NextEdge;

              };

              struct _vertex

              {

              char CarId[10];

              int x,

              y;

              vertex *NextVertex;

              edge *NextEdge;

              };

              [/CODE]

              how should i buil my 2D linked list ?

              Comment

              Working...