⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 init.c.bak

📁 图书管理系统
💻 BAK
字号:
/* file_name:	init.c
 * author:	wangtiezhen miuliang @ Xidian University
 * description:	
 */
struct stu *inputstu(int num, int password,char name[], int age, char addr[]) ;
int readstudent(void) ;

int readstudent(void) {
        FILE *fp;
        int i = 0;
        if( (fp = fopen("student", "r") ) == NULL) {
                printf("It cann't opean file\n"); /* Cannot open the file */
                return -1;
        }
        while( !feof(fp) ) {
                int num, age,password;
                char name[20], addr[20];
                fscanf(fp, "%s%d%d%d%s", name, &num,&password, &age, addr);
                inputstu(num, password,name, age, addr);
                if(!feof(fp)){
                	i++;
                }
        }
        return i;
}
struct stu *inputstu(int num, int password,char name[], int age, char addr[]) {
        struct stu *p,*q;
        p=(struct stu *)malloc(sizeof(struct stu));
        p->num = num;
        p->password=password;
        strcpy(p->name,name);
        strcpy(p->addr,addr);
        p->age = age;
        p->lchild=NULL;
        p->rchild=NULL;
        if((p->num)!=0) {
                q=stubt;
                if(q==NULL)
                        stubt=p;

                else {
                        while((q->lchild!=p)&&(q->rchild)!=p) {
                                if((p->num)<(q->num)) {

                                        if(q->lchild!=NULL)
                                                q=q->lchild;
                                        else
                                                q->lchild=p;
                                } else {
                                        if(q->rchild!=NULL) {
                                                q=q->rchild;
                                        } else
                                                q->rchild=p;
                                }
                        }

                }
        }
        return stubt;
}

/* Begin:
 * stu travel;
 */
int print_stu(struct stu* root)
{
//	putchar('p');
	printf("num:%d\tpass:%d\tname:%s\tage:%d\taddr:%s\n", root->num, root->password, 
		root->name, root->age, root->addr);
	return;
}

int tree_visit_stu(struct stu* root, int f(), int style)
{
//	putchar('j');
	if(root == NULL)
	{
		return 0;
	}
	if(style == 0)
		(*f)(root);
	tree_visit_stu (root->lchild, f, style );
	if(style == 1)
		(*f)(root);
	tree_visit_stu (root->rchild, f, style );
	if(style == 2)
		(*f)(root);
}
/* End:
 * stu travel;
 */



/* Begin:
 * stu find;
 */
struct stu* stu_name_pointer(struct stu* root, char* find_name)
{
	struct stu* t = NULL;
//	putchar('j');
	if(root == NULL){
		return NULL;
	}
	if(!strcmp(find_name , root->name)){
//		printf("find it!");
		return root;
	}
//	putchar('J');
	if((t = stu_name_pointer (root->lchild, find_name )) != NULL){
		return t;
	}
	if((t = stu_name_pointer (root->rchild, find_name )) != NULL){
		return t;
	}
//	printf("\t");
	return NULL;
}
/* End:
 * stu find;
 */


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -