Home > Back-end >  Why switch statements are execute the default input
Why switch statements are execute the default input

Time:01-13

# include
# include
# include

Struct student
{
Char num [10].
Char name [15].
Char preject [20].
Int reward;
};
Struct Node
{
Struct student data;
Struct Node * next;

};
Struct Node * createlist ()
{
Struct Node * listHeadNode=(struct Node *) malloc (sizeof (struct Node));
ListHeadNode - & gt; Next=NULL;
Return listHeadNode;
}
Struct Node * createNode (struct student data)
{
Struct Node * newNode=(struct Node *) malloc (sizeof (struct Node));
NewNode - & gt; data=https://bbs.csdn.net/topics/data;
NewNode - & gt; Next=NULL;
Return the newNode;
}
//insert
Void insertNodeByHead (struct Node * listHeadNode, struct student data)
{
Struct Node * newNode=createNode (data);
NewNode - & gt; Next=listHeadNode - & gt; Next;
ListHeadNode - & gt; Next=newNode;
}
//delete;
Void deleteNodeByAppoinName (struct Node * listHeadNode, char * name)
{
Struct Node * posFrontNode=listHeadNode;
Struct Node * posNode=listHeadNode - & gt; Next;
If (posNode==NULL)
{
Printf (" no related content, unable to delete \ n ");
return;
}
The else
{
While (STRCMP (posNode - & gt; Data. The name, the name))
{
PosFrontNode=posNode;
PosNode=posFrontNode - & gt; Next;
If (posNode==NULL)
{
Printf (" no related content, unable to delete \ n ");
}}
PosFrontNode - & gt; Next=posNode - & gt; Next;
Free (posNode);
}
}
//find
Struct Node * searchNodeByAppoinNum (struct Node * listHeadNode, char * num)
{
Struct Node * pMove=listHeadNode - & gt; Next;
If (pMove==NULL)
Return pMove;
The else
While (STRCMP (pMove - & gt; Data. The num, num));
{
PMove=pMove - & gt; Next;
If (pMove==NULL)
exit(0);
}
Return pMove;
}

Void printNode (struct Node * curNode)
{
Printf (" enquiries \ t name \ \ t t project award \ n ");
Printf (" % s \ \ t t t % d % s \ \ t % s \ n ", curNode - & gt; Data. The num, curNode - & gt; Data. The name, curNode - & gt; Data. Preject, curNode - & gt; Data. The reward);

}
//print
Void printlist (struct Node * listHeadNode)
{
Struct Node * pMove=listHeadNode - & gt; Next;
Printf (" enquiries \ t name \ \ t t project award \ n ");
While (pMove)
{
Printf (" % s \ \ t t t % d % s \ \ t % s \ n ", pMove - & gt; Data. The num, pMove - & gt; Data. The name, pMove - & gt; Data. Preject, pMove - & gt; Data. The reward);
PMove=pMove - & gt; Next;
printf("\n");
}
}
Void readinfofromfile (char * fileName, struct Node * listHeadNode)
{
The FILE * fp=fopen (fileName, "r");
If (fp==NULL)
{
Fp=fopen (fileName, "w");
}
Struct student tempData;
While (fscanf (fp, "% s \ % s \ t t t % d \ % s \ n", tempData. Num, tempData. Name, tempData. Preject, tempData. Reward)!=(EOF)
{
InsertNodeByHead (listHeadNode, tempData);
Memset (& amp; TempData, 0, sizeof (tempData));
}
fclose(fp);
}
Void saveinfotofile (char * fileName, struct Node * listHeadNode)
{
The FILE * fp=fopen (fileName, "w");
Struct Node * pMove=listHeadNode - & gt; Next;
While (pMove)
{
Fprintf (fp, "% s \ \ t t t % d % s \ \ t % s \ n", pMove - & gt; Data. The num, pMove - & gt; Data. The name, pMove - & gt; Data. Preject, pMove - & gt; Data. The reward);
PMove=pMove - & gt; Next;
}
fclose(fp);
}
Void systemMenu ()
{printf (" * * * * * * * * * * * * * * * welcome to graduate student scientific research reward system * * * * * * * * * * * * * * * * * * \ n ");
Printf (" \ t0. [exit systems] \ n ");
Printf (" \ t1. [insert information] \ n ");
Printf (" \ t2. [delete information] \ n ");
Printf (" \ t3. [browse information] \ n ");
Printf (" \ t4/modify information \ n ");
Printf (" \ t5. [information] \ n ");
Printf (" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf (" please enter 0 ~ 5 number one ");
}
Void keyDown ()
{
Int userkey;
Struct student tempData;
The scanf (" % d, & amp; Userkey ");
The switch (userkey)
{
Case '0' :
Printf (" \ t \ t0. [exit systems] \ n ");
system("pause");
exit(0);
Case '1' :
Printf (" \ \ t t1. [insert information] \ n ");
Printf (" please enter the student's student id, name, project and rewards, ");
The scanf (" % d % d % s % s ", tempData. Num, tempData. Name, tempData. Preject, tempData. Reward);
Struct Node * list; InsertNodeByHead (list, tempData);
Saveinfotofile (" student. TXT ", a list);
break;
Case '2' :
Printf (" \ \ t t2. [browse information] \ n ");
Printlist (list);
break;
Case '3' :
Printf (" \ \ t t3. [delete information] \ n ");
Printf (" please enter the names of the students want to delete: ");
The scanf (" % s ", tempData. Name);
DeleteNodeByAppoinName (list, tempData. Name);
Saveinfotofile (" student. TXT ", a list);
break;
Case '4' :
Printf (" \ t \ t4/modify information \ n ");
Printf (" please enter the student's student id: to modify ");
The scanf (" % s ", tempData. Num);
If (searchNodeByAppoinNum (list, tempData. Num)==NULL)
Printf (" relevant information was not found ");

The else
{
Struct Node * curNode=searchNodeByAppoinNum (list, tempData. Num);
Printf (" please enter the new student awards information: student id, name, project, rewards ");
The scanf (" % d % d % s % s ", curNode - & gt; Data. The num, curNode - & gt; Data. The name, curNode - & gt; Data. Preject, curNode - & gt; Data. The reward);
Saveinfotofile (" student. TXT ", a list);
}
break;
Case '5' :
Printf (" \ t \ t5. [information] \ n ");
Printf (" please enter student id to find students: ");
The scanf (" % s ", tempData. Num);
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related