C,function不能用
小弟刚学C 请多多指教这是我的作业
不知道为什么我的第三个function不可以用。。。就是要印出我输入过的资料不能出来
程序代码:#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node
{
char *student_name;
char *gender;
char *course;
int *student_number;
struct node *next;
struct node *prev;
}*newnode, *firstPtr,*temp,student;
void insert_new(char *name, char *gender, char *course, int *number){
newnode = (struct node*)malloc(sizeof (struct node));
newnode->student_name = name;
newnode->gender = gender;
newnode->course = course;
newnode->student_number = number;
newnode->next = NULL;
if (firstPtr == NULL)
{
firstPtr = newnode;
}
else
{
temp = firstPtr;
while (temp->next != NULL)
{
temp = temp->next;
}
temp->next = newnode;
firstPtr = temp;
}
printf("Insert success\n");
printf("Press any key to go back main menu\n");
getch();
}
void insert_last(){
}
void print_begin(){
if (firstPtr == NULL)
printf("List is empty\n");
else
{
struct node *tempdisplay;
tempdisplay = firstPtr;
while (tempdisplay != NULL)
{
printf("%s\n", tempdisplay->student_name);
printf("%s\n", tempdisplay->gender);
printf("%s\n", tempdisplay->course);
printf("%d\n", tempdisplay->student_number);
tempdisplay = tempdisplay->next;
}
}
printf("\n\nPress any key to go back main menu\n");
getch();
}
void print_last(){
}
void remove_student(){
}
main()
{
firstPtr=NULL;
char name;
char gender;
char course;
int number;
int main_choice;
do{
printf("\n");
printf("\n");
printf("\n");
printf(" 1.Add a new student to the beginning\n");
printf(" 2.Add a new student to the end\n");
printf(" 3.Print out the entire list from the beginning\n");
printf(" 4.Print out the entire list from the end\n");
printf(" 5.Remove a student from the list\n");
printf(" 6.Quit the program\n");
printf("\n\nEnter the number of the options\n");
scanf("%d", &main_choice);
switch (main_choice){
case 1: {
printf("Enter the name of the student\n");
scanf("%s", &name);
printf("Enter the gender of the student\n");
scanf("%s", &gender);
printf("Enter the course of the student\n");
scanf("%s", &course);
printf("Enter the number of the student\n");
scanf("%d", &number);
insert_new(name,gender,course,number);
}break;
case 2: insert_last(); break;
case 3: print_begin(); break;
case 4: print_last(); break;
case 5: remove_student(); break;
case 6:{
printf("\n\n\nThe program is closing...\n...\n");
return 0;
break;
}
}
system("cls");
} while (main_choice != 6);
}[ 本帖最后由 chaicai333 于 2014-4-13 03:25 编辑 ]




