Home > Back-end >  Function of the scanf program can't input to solve
Function of the scanf program can't input to solve

Time:11-16

 # include 
#include
# define the maximum number of vertex VERTEX_MAX//figure 26
32767//# define MAXVALUE maximum (can be set as one of the biggest integer)
Typedef struct
{
Int Vertex [VERTEX_MAX];//save the vertex information (serial Numbers or letters)
Int Edges [VERTEX_MAX] [VERTEX_MAX];//save the edge of the right
Int isTrav [VERTEX_MAX];//traverse sign
Int VertexNum;//the number of vertices
Int EdgeNum;//edge number
Int GraphType;//diagram types (0: undirected graph, 1: directed graph)
} MatrixGraph;//define the adjacency matrix structure

Void Createlin MatrixGraph * (G);//create the adjacency matrix figure
Void Outlin MatrixGraph * (G);//output adjacency matrix

Void Createlin (MatrixGraph * G)//create the adjacency matrix figure
{
Int I, j, k, weight;
Int s, e;//the edge of the initial vertex
Printf (" input each vertex information \ n ");
for (i=0; i{

Printf (" % d vertices: ", I);
The scanf (" % d ", & amp; (G - & gt; Vertex [I]));//save to each vertex array element
}
Printf (" input form two vertices and weights of each side of the (separated by commas) : \ n ");
For (k=0; K{

Printf (" % d side: ", k + 1);
The scanf (" % d, % d, % d ", & amp; S, & amp; E, & amp; Weight);
for (i=0; S!!!!=G - & gt; Vertex [I]; i++);//to look for in the existing vertex starting point
For (j=0; E!=G - & gt; Vertex [j]; J++);//to look for in the existing vertex knot at the end of the
G - & gt; Edges [I] [j]=weight;//the corresponding position to save weight, says there is a side
If (G - & gt; GraphType==0)//if the undirected graph
G - & gt; Edges [j] [I]=weight;//in diagonal position to save weight
}
}

Void Outlin (MatrixGraph * G)//output adjacency matrix
{
int i, j;
For (j=0; jPrintf (" \ t % d ", the G & gt; Vertex [j]);//output at line 1 vertex information
printf("\n");
for (i=0; i{
Printf (" % d ", the G & gt; Vertex [I]);
For (j=0; j{
If (G - & gt; Edges [I] [j]==MAXVALUE)//if a maximum weight of
Printf (" \ t up ");//output infinity symbol
The else
Printf (" \ t % d ", the G & gt; Edges [I] [j]);//output edge weight
}
printf("\n");
}
}

Int main ()
{
MatrixGraph G;//save the adjacency matrix structure defined figure
int i, j;
Printf (" input to generate chart type (0: undirected graph, 1: directed graph) : ");
The scanf (" % d ", & amp; G.G raphType);//diagram type

Printf (" input figure on the number of vertices and edges number: ");
The scanf (" % d, % d ", & amp; G.V ertexNum, & amp; G.E dgeNum);//input graph vertices and the number of edges

for (i=0; iFor (j=0; jG.E dges [I] [j]=MAXVALUE;//matrix of each element in the set value of the maximum
Createlin (& amp; G);//create preserved by adjacency list figure
Printf (" adjacency matrix data is as follows: \ n ");
Outlin (& amp; G);
Getch ();
return 0;
}
program box directly output the first vertex: second vertex: third vertex: the fourth vertex: fifth vertex: and does not perform Outlin function, only vc630 can normal input/output tried several other compilers cannot, solving

CodePudding user response:

The inside of the printf % and variable of one to one correspondence relation
The scanf % and variables and the variables inside before add don't add & amp; One-to-one correspondence relationship
Is the place that C code is very easy to get wrong, and generally don't compile error,
So during the compilation of source code is worth specially carefully check it again and even many times before,

CodePudding user response:

Behind every last without \ n printf plus fflush (stdout);
In each don't want to receive buffer in front of the old content affected the scanf and rewind (stdin);
In addition, please check the return values of the scanf
//in the future, please use 
Int c;
The scanf (" % c ", & amp; C);
//, is changed to
Char s [2];
Int c;
The scanf (" % 1 s ", s);
C=s [0];

CodePudding user response:

Don't know what call can't input, check yourself:
1. You can view the scanf return values, see
successfully read several variables2. The scanf (" % d, % d "written as mean you input must be a comma to separate two Numbers (with Spaces)
3. Could be somewhere else mistake caused you can not get the correct results (step through and set breakpoint debugging (VS IDE compilation connection through later, press F10 or F11 key step, press Shift + F11 exit the current function; In a press F9 set breakpoints after press F5 execution stops at the breakpoint,) is one of the programmers must master the skills,

CodePudding user response:

reference qq423399099 reply: 3/f
don't know what call can't input, check yourself:
1. You can view the scanf return values, see
successfully read several variables2. The scanf (" % d, % d "written as mean you input must be a comma to separate two Numbers (with Spaces)
3. Could be somewhere else mistake caused you can not get the correct results (step through and set breakpoint debugging (VS IDE compilation connection through later, press F10 or F11 key step, press Shift + F11 exit the current function; In a row after press F9 set breakpoints press F5 execution stops at the breakpoint,) is one of the programmers must master the skills,)
is the scanf is originally I want to be on the keyboard input values but now program runs don't give me the opportunity to enter to see the return value

CodePudding user response:

You have a compiler problem,
I here VS can be correctly input
http://blog.csdn.net/cometnet/article/details/19551125

CodePudding user response:

reference 5 floor qq423399099 reply:
your compiler has a problem,
I here VS can be correctly input
http://blog.csdn.net/cometnet/article/details/19551125
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, you don't say I didn't think of the things I wrote a few weeks before operation is right I tend to program and wrong classification today for the first time, try is right and then straight to collapse!!!!!

CodePudding user response:

 
#include
#include

# define the maximum number of vertex VERTEX_MAX//figure 26
32767//# define MAXVALUE maximum (can be set as one of the biggest integer)

Typedef struct
{
Int Vertex [VERTEX_MAX];//save the vertex information (serial Numbers or letters)
Int Edges [VERTEX_MAX] [VERTEX_MAX];//save the edge of the right
Int isTrav [VERTEX_MAX];//traverse sign
Int VertexNum;//the number of vertices
Int EdgeNum;//edge number
Int GraphType;//diagram types (0: undirected graph, 1: directed graph)
} MatrixGraph;//define the adjacency matrix structure

Void Createlin MatrixGraph * (G);//create the adjacency matrix figure
Void Outlin MatrixGraph * (G);//output adjacency matrix

Void Createlin (MatrixGraph * G)//create the adjacency matrix figure
{
Int I, j, k, weight;
Int s, e;//the edge of the initial vertex

Printf (" input each vertex information \ n ");
for (i=0; i{

Printf (" % d vertices: ", I);
The scanf (" % d ", & amp; (G - & gt; Vertex [I]));//save to each vertex array element
}
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related