暑假用了三天写的C语言课程设计———学生通讯录 ,还有待完善,就暂且称为1.0版本吧(初具功能,但有缺陷)。
使用的开发软件是 C/C++程序设计学习与试验系统,这个开发软件感觉还不错,支持C++还有中文显示,并且里面还有大量的习题。不过如果想要是自己的编程更加规范,还是TC++3.0比较好。
学生通讯录 主要用到的知识点主要是链表的操作如:建立链表、删除链表、插入链表、查找链表等
#include<stdio.h>
#include<windows.h>
#include<conio.h>
/*预定义*/
#define MAX 50
#define OK 1
#define TRUE 1
#define ERROR 0
#define FALSE 0
/*结构体定义*/
typedef struct address
{
char num[20];
char name[20];
char phone[25];
struct address *next; /*结构体指针*/
};
/*全局变量*/
FILE *fp,*pf; /*文件指针*/
struct address * head;
int i=0; /*计算信息个数*/
/*函数声明*/
void gotoxy(int x,int y); /*光标定位函数*/
struct address* create(void);
int print(struct address *head);
int search(struct address *head);
struct address *insert(struct address *head);
struct address *dele(struct address *head);
struct address *sort(struct address *head);
int save(struct address *head);
struct address * load(void);
void gotoxy(int x,int y) /*光标定位函数*/
{
COORD coord;
coord.X=x;
coord.Y=y;
SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), coord );
}
/*建立链表函数*/
struct address* create(void) /*()里返回类型可以是void或者struct address * head*/
{ /*之所以要返回是因为其他函数要用到头指针*/
int flag1=0;
char ch;
struct address *p,*q;
system("cls");
i=0;
if(!(p=q=(struct address*)malloc(sizeof(struct address))))
{
printf("内存分配出现错误!/n");
printf("请按任意键返回主菜单.../n");
getch();
return ERROR;
}
head=NULL;
printf("请输入学生的信息:学号:/n");
scanf("%s",p->num);
printf("请输入学生的信息:名字:/n");
scanf("%s",p->name);
printf("请输入学生的信息:电话:/n");
scanf("%s",p->phone);
head=p;
q=p;
flag1=1;
i++;
while(flag1)
{
printf("还要继续输入码?y/n/n");
scanf("%s",&ch); /*不能用%c不知道为什么*/
if(ch=='y')
{
if(!