Home > Back-end >  Elder people give advice or comments, please list
Elder people give advice or comments, please list

Time:11-19

#include
#include
# define LEN sizeof (struct Student)
Struct Student
{
Long int data;
Float score;
Struct Student * next;
};
int n;
Struct Student * creat (void)
{
Struct Student * (p1, p2, * head;
The head=NULL;

P1 p2==(struct Student *) malloc (LEN);
n=0;
The scanf (" % d, % f ", & amp; P1 - & gt; The data, & amp; P1 - & gt; Score);
While (p1 - & gt; The data!=0)
{
N=n + 1;
If (n==1) head=p1;
The else p2 - & gt; Next=p;
P1 p2=;
P1=(struct Student *) malloc (LEN);
The scanf (" % d, % f ", & amp; P1 - & gt; The data, & amp; P1 - & gt; Score);
}
The p2 - & gt; Next=NULL;
Return the head;
}
Print (struct Student * head)
{
Struct Student * p;
P=the head;
While (p - & gt; Data)
{
Printf (" % d % 1 f \ n ", p - & gt; The data, p - & gt; Score);
P=p - & gt; Next;
}
}
Void main ()
{
Struct Student * t;
T=creat ();
Print (t);
}
This is a simple list of creation and output, but I'm not out of any compile-time errors, run out quite a few problems
1, 1 is in the input score, enter a decimal number, press enter to output directly, and there is a problem in the output screenshots:
2, 2 is in the case of not enter the decimal point, after the output data by 10,
This is how to return a responsibility, meng directly,

CodePudding user response:

The scanf (); Function is formatted input of meaning, the format is what you write (" % d, % f "), then you should also be as input 4564 32.0 to 4564,32.0 wouldn't be a input decimal output directly;
You find every time output data by 10 should be or format, the scanf don't think you input the second number, so I think the second number is zero, you haven't separate formatting output of two Numbers, you enter 123, 123, the program think you input is 123, 0 123, 0 so give you 1230, 1230, the output looks like by 10

CodePudding user response:


Also not ah, add don't add, or useless

CodePudding user response:


The results of your program that I run, you see my input

CodePudding user response:

You have a look at the scanf input format is what, is missing a comma, and is a comma in English;

 # include 
#include

# define LEN sizeof (struct Student)

Struct Student
{
Long int data;
Float score;
Struct Student * next;
};

int n;
Struct Student * creat (void)
{
Struct Student * (p1, p2, * head;
The head=NULL;

P1 p2==(struct Student *) malloc (LEN);
n=0;
//the scanf (" % d, % f ", & amp; P1 - & gt; The data, & amp; P1 - & gt; Score);
The scanf (" % f, % ld ", & amp; P1 - & gt; The data, & amp; P1 - & gt; Score);
While (p1 - & gt; The data!=0)
{
N=n + 1;
If (n==1)
The head=p1;
The else p2 - & gt; Next=p;
P1 p2=;
P1=(struct Student *) malloc (LEN);
//the scanf (" % d, % f ", & amp; P1 - & gt; The data, & amp; P1 - & gt; Score);
The scanf (" % f, % ld ", & amp; P1 - & gt; The data, & amp; P1 - & gt; Score);
}
Free (p1);//p1 didn't join the chain table, should release
The p2 - & gt; Next=NULL;
Return the head;
}
//print (struct Student * head)
Void print (struct Student * head)
{
Struct Student * p;
P=the head;
//while (p - & gt; Data)
While (p)
{
//printf (" % d % 1 f \ n ", p - & gt; The data, p - & gt; Score);
Printf (" % ld \ t % 1 f \ n ", p - & gt; The data, p - & gt; Score);
P=p - & gt; Next;
}
}
//void main ()
Int main ()
{
Struct Student * t;
T=creat ();
Print (t);
}

For your reference ~

Other problems to see code ~ as above

CodePudding user response:

references 4 building self-confidence boy reply:
you have a look at the scanf input format is what, is missing a comma, and is a comma in English;

 # include 
#include

# define LEN sizeof (struct Student)

Struct Student
{
Long int data;
Float score;
Struct Student * next;
};

int n;
Struct Student * creat (void)
{
Struct Student * (p1, p2, * head;
The head=NULL;

P1 p2==(struct Student *) malloc (LEN);
n=0;
//the scanf (" % d, % f ", & amp; P1 - & gt; The data, & amp; P1 - & gt; Score);
The scanf (" % f, % ld ", & amp; P1 - & gt; The data, & amp; P1 - & gt; Score);
While (p1 - & gt; The data!=0)
{
N=n + 1;
If (n==1)
The head=p1;
The else p2 - & gt; Next=p;
P1 p2=;
P1=(struct Student *) malloc (LEN);
//the scanf (" % d, % f ", & amp; P1 - & gt; The data, & amp; P1 - & gt; Score);
The scanf (" % f, % ld ", & amp; P1 - & gt; The data, & amp; P1 - & gt; Score);
}
Free (p1);//p1 didn't join the chain table, should release
The p2 - & gt; Next=NULL;
Return the head;
}
//print (struct Student * head)
Void print (struct Student * head)
{
Struct Student * p;
P=the head;
//while (p - & gt; Data)
While (p)
{
//printf (" % d % 1 f \ n ", p - & gt; The data, p - & gt; Score);
Printf (" % ld \ t % 1 f \ n ", p - & gt; The data, p - & gt; Score);
P=p - & gt; Next;
}
}
//void main ()
Int main ()
{
Struct Student * t;
T=creat ();
Print (t);
}

For your reference ~

Other problems to see code ~ as
is the scanf commas should be yes, estimation is my compile software out of the question, I still have some details and note that is your code to run with my brother has a problem, I have to change the software, thanks brother

CodePudding user response:

references 4 building self-confidence boy reply:
you have a look at the scanf input format is what, is missing a comma, and is a comma in English;

 # include 
#include
  • Related