Home > Back-end >  Vs scanf_s error
Vs scanf_s error

Time:10-13

Is there a big help to have a look at this program, online compilation sure, vs run there will always be wrong

#include
Void the Output (struct Student stu [], int n);
Int the Insert (struct Student stu [], int n, struct Student stu1);
Struct Student {
Int id;
Char name [20].
float score;
};
Int main ()
{
Struct Student stu [10]={
{101, "Tom," 86},
{103, "Jerry," 68},
{105, "Mickey", 77},
{107, "Donald", 90}
};
Int n=4, id, k;
Struct Student stu1;
The Output (stu, n);
Printf (" please input to add student information: \ n ");
Scanf_s (" % f % d % s \ n ", & amp; Stu1. Id, stu1. Name, sizeof (stu1. Name), & amp; Stu1. Score);
N=Insert (stu, n, stu1);
The Output (stu, n);
return 0;
}

Void the Output (struct Student stu [], int n)
{
int i;
for (i=0; I & lt; n; I++)
{
Printf (" % f % d % s \ n ", stu [I] id, stu [I]. Name, stu [I] score).
}

}

Int the Insert (struct Student stu [], int n, struct Student stu1)
{
int i;
For (I=n - 1; I & gt;=0 & amp; & Stu [I]. Id & gt; Stu1. Id; I -)
{
Stu [I + 1)=stu [I];
}
Stu [I + 1)=stu1;
Return the n + 1;
}

CodePudding user response:

Scanf_s (" % d % s % f ", & amp; Stu1. Id, stu1. Name, sizeof (stu1. Name), & amp; Stu1. Score);
\ n problem, mentally, what do you want to put a newline, like printf is not these two functions corresponding

CodePudding user response:

What's wrong?
Try sizeof (stu1. Name) to 20

CodePudding user response:

Don't need to add a newline character

CodePudding user response:

Remove the newline character is correct
  • Related