Home > Back-end >  Small white help, questions about structure of arrays and Pointers
Small white help, questions about structure of arrays and Pointers

Time:09-19

#include
#include
Struct student {
Char name [20].
Char sex;
int age;
};
Int main ()
{
Struct student s [5];
Struct student * p=s;
Void input (struct student *);
Void show (struct student *);
Void sort (struct student *);
Input (p);
Sort (p);
Show (p);
system("pause");
return 0;
}

Void input (struct student * s)
{
Printf (" input information five students \ n ");
Printf (" name gender \ \ t t age \ n ");
int i;
for (i=0; I & lt; 5; I++)
Scanf_s (" % s % c % d ", [I] s name, & amp; S [I]. Sex, & amp; S [I]. Age);
}
Void show (struct student * s)
{
Printf (" name gender \ \ t t age \ n ");
int i;
for (i=0; I & lt; 5; I++)
Printf (" % 5 s % 5 c % d ", [I] s name, s [I] sex, s [I] age);
}
Void sort (struct student * s)
{
Int I, j, min;
Struct student t;
for (i=0; I & lt; 4. I++)
Min=I;
For (j=I + 1; J & lt; 5; J++)
If (s [j]. Journal of age & lt; S [r]. Min age)
Min=j;
If (min!=I)
{
T=s [I];
S [I]=s/min;
S [min]=t;
}

}
Why an error code 0 xc0000005: when writing position 0 x01340000 access conflict, should how to fix it

CodePudding user response:

The input () function in scanf_s code is modified to
 scanf_s (" % s % c % d ", [I] s name, 20, & amp; S [I] sex, 1, & amp; S [I]. Age); 

Scanf_s () is the scanf security version, you need to specify the save data string, character variables such as length,
VS2015 debugging c + + version

  • Related