void add(SqList *p_seq)
{
printf("Please enter information:\n");
while (1)
{
printf("ID: ");
scanf("%s", p_seq->elem[p_seq->length].stuID);
if (strlen(p_seq->elem[p_seq->length].stuID) >= ID_SIZE)
{
printf("It's too long, enter again\n");
sleep(1);
system("cls");
}
else
{
break;
}
}
while (1)
{
printf("Name: ");
scanf("%s", p_seq->elem[p_seq->length].stuName);
if (strlen(p_seq->elem[p_seq->length].stuName) >= NAME_SIZE)
{
printf("It's too long, enter again\n");
sleep(1);
system("cls");
}
else
{
break;
}
}
while (1)
{
printf("Score: ");
scanf("%lf", &p_seq->elem[p_seq->length].stuScore);
if (p_seq->elem[p_seq->length].stuScore <0 || p_seq->elem[p_seq->length].stuScore > 100)
{
printf("The score is percentage system\n");
sleep(1);
system("cls");
}
else
{
break;
}
}
p_seq->length++;
}
void NodeDelete(SqList *p_seq, int locate)
{
for (int i=locate; i<=p_seq->length; i++)
{
memccpy((p_seq->elem[i-1]).stuID, (p_seq->elem[i]).stuID, '\0', ID_SIZE);
memccpy((p_seq->elem[i-1]).stuName, (p_seq->elem[i]).stuName, '\0', NAME_SIZE);
(p_seq->elem[i-1]).stuScore = (p_seq->elem[i]).stuScore;
}
p_seq->length--;
}
stuPtr search(stuPtr p, size_t len, char *target)
{
for (unsigned i=0; i<len; i++)
{
if (strcmp(p[i].stuID, target) == 0)
{
return (p+i);
}
else if (strcmp(p[i].stuName, target)== 0)
{
return (p+i);
}
}
return NULL;
}
void print(StuData *elem, size_t len)
{
printf(" ID Name Score\n");
printf(" -----------------------------------------------\n");
if (len <= 0)
{
printf("\a\n\t\tWarning: NO data exist!\n");
}
else
{
unsigned count = 0;
for (unsigned i=0; i<len; i++)
{
printf("%3d-", ++count);
printf(" %s\t\t", elem[i].stuID);
printf(" %s\t\t", elem[i].stuName);
printf(" %.2lf\n", elem[i].stuScore);
}
printf(" num: %lu\n", len);
}
printf(" -----------------------------------------------\n");
}