473,386 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

fscanf issue

momotaro
357 100+
is it correct to write that:
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. fscanf(InputFile, "%s %d %d", NewVertex->CarId, NewVertex->x, NewVertex->y);
  4.  
  5.  
Nov 23 '07 #1
6 1080
JosAH
11,448 Expert 8TB
is it correct to write that:
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. fscanf(InputFile, "%s %d %d", NewVertex->CarId, NewVertex->x, NewVertex->y);
  4.  
  5.  
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
Nov 23 '07 #2
momotaro
357 100+
hence i dont no where is the problem in those lines of code:
Expand|Select|Wrap|Line Numbers
  1.  for(i = 0; i < vehicules; i++) 
  2.  
  3. {
  4.  
  5. NewVertex = CreatVertex();
  6.  
  7. // up to here ok
  8.  
  9. fscanf(InputFile, "%s %d %d", NewVertex->CarId, NewVertex->x, NewVertex->y);
  10.  
  11. }
  12.  
  13.  
this is the file:
5

250

Toto 25 50

Foo 20 50

X 50 100

Y -100 -200

Z -5 150

the program cruch
Nov 23 '07 #3
JosAH
11,448 Expert 8TB
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
Nov 23 '07 #4
momotaro
357 100+
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?

Expand|Select|Wrap|Line Numbers
  1.  typedef struct _list list; 
  2.  
  3. struct _list
  4. {
  5. edge *E;
  6. vertex *V;
  7. list *NextVertex,
  8. *NextEdge;
  9. } ;
  10.  
Nov 23 '07 #5
momotaro
357 100+
or:

Expand|Select|Wrap|Line Numbers
  1.  typedef struct _edge edge; 
  2. typedef struct _vertex vertex;
  3. typedef struct _edgelist edgelist;
  4. typedef struct _vertexlist vertexlist;
  5.  
  6. struct _edge
  7. {
  8. CarID[10];
  9. int distance;
  10. };
  11.  
  12. struct _vertex
  13. {
  14. CarID[10];
  15. int x,
  16. y;
  17. };
  18.  
  19. struct edgelist
  20. {
  21. edge *E;
  22. edgelist *next;
  23. };
  24.  
  25. struct edgevertex
  26. {
  27. vertex *V;
  28. vertexlist *next;
  29. }; 
  30.  
if you have any better implimentation please help!
Nov 23 '07 #6
momotaro
357 100+
originaly am using these structers to impliment my graph:

Expand|Select|Wrap|Line Numbers
  1.  typedef struct _edge edge; 
  2.  
  3. typedef struct _vertex vertex;
  4.  
  5.  
  6.  
  7. struct _edge
  8.  
  9. {
  10.  
  11. char CarId[10];
  12.  
  13. int distance;
  14.  
  15. edge *NextEdge;
  16.  
  17. };
  18.  
  19. struct _vertex
  20.  
  21. {
  22.  
  23. char CarId[10];
  24.  
  25. int x,
  26.  
  27. y;
  28.  
  29. vertex *NextVertex;
  30.  
  31. edge *NextEdge;
  32.  
  33. };
  34.  
  35.  
how should i buil my 2D linked list ?
Nov 23 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Psibur | last post by:
Hello, trying to get back into c and was having issue with reading a simple text file with an aribtrary # of lines with 3 int's per line, with the eventual purpose of putting each int into an...
7
by: Thomas Sourmail | last post by:
Hi, I hope I am missing something simple, but.. here is my problem: I need my program to check the last column of a file, as in : a b c d target ref 0 0 0 0 1 a 1 0 0 0 1.5 b 2 0 0 0 2 c
37
by: PeterOut | last post by:
I am using MS Visual C++ 6.0 on Windows XP 5.1 (SP2). I am not sure if this is a C, C++ or MS issue but fscanf has been randomly hanging on me. I make the call hundreds, if not thousands, of...
59
by: David Mathog | last post by:
Apologies if this is in the FAQ. I looked, but didn't find it. In a particular program the input read from a file is supposed to be: + 100 200 name1 - 101 201 name2 It is parsed by reading...
1
momotaro
by: momotaro | last post by:
I have a small problem with the last fscanf in this function...every thing is logic in there but can't find the problem... plz help node *BuildGraph() { int range, vehicules, i, j,...
3
by: Shisou | last post by:
Hey bytes community! this one is a really strange issue I ran into and I'm hoping you all can shine some light on it for me. This is written in C, not C++ I'm working on a program that reads...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.