琥珀玲珑
琥珀玲珑的世界,也是你们的世界哦。大家一起来吧!!!!

文章分类 -  C 语言

C 语言
顺序表(C语言)数据结构
摘要:#include#include#define OK 1#define ERROR 0typedef char Status;//换名#define List_Size 10typedef struct //换名{char *elem; //成员指针int length; //长度int listsize; //现有的长度}SqList;SqList C_NullList() //初始化顺序表//void C_NullList(){SqList L;L.elem=(Status *)malloc(List_Size *sizeof(Status)); //创建类型的Status *(还是指针) 阅读全文
posted @ 2013-11-17 14:09 琥珀玲珑 阅读(289) 评论(0) 推荐(0)
递归中的阶乘
摘要:#includeint fac(int n){int f;if(n<0) //n不能小于0printf("n小于0,data error!");elseif(n==0||n==1) //当n=1或0时,n!=1 f=1;elsef=fac(n-1)*n; //当n大于1时,n!=n*(n-1)!return f;}int main(){int n,sum;printf("please enter integer number:");scanf("%d",&n);sum=fac(n);printf("sum=%d 阅读全文
posted @ 2013-07-19 16:38 琥珀玲珑 阅读(106) 评论(0) 推荐(0)
使用指针
摘要:#include#include#define size 10int i,a[size],*p; //定义全局变量i,全局数组a[size],全局指针pvoid shuru1(){ FILE *fp;if((fp=fopen("shu.dat","w"))==NULL) { printf("can't open file!\n"); exit(0); }printf("请输入内容:");for(i=0;i<size;i++){ scanf("%d",&a[i]); fput 阅读全文
posted @ 2013-07-19 16:05 琥珀玲珑 阅读(132) 评论(0) 推荐(0)
静态链表
摘要:#includetypedef struct student{int num;float score;struct student *next;}stu; //命名了一个新的类型名代表结构体类型void create(){stu a,b,c,*head,*p; //a,b,c为三个链表的结点,head为头结点a.num=101;a.score=85.5;b.num=102;b.score=90.5;c.num=103;c.score=95;head=&a;a.next=&b;b.next=&c;c.next=NULL;p=head; //使p指向头结点printf(&q 阅读全文
posted @ 2013-07-18 09:58 琥珀玲珑 阅读(101) 评论(0) 推荐(0)
职工信息存入文件employee,再抽取部分信息存入另一个文件employee_type
摘要:#include#include#include#define size 3struct employee{ char name[6]; //姓名 char num[8]; //编号 char sex[2]; //性别int age; //年龄 char addr[10]; //地址 int money; //工资 char health[4]; //身体健康程度 char cul[4]; //文化程度 }emp[size]; //employee结构体struct employee_type{ char name[6]; int money;}empl[size]; //employee_t 阅读全文
posted @ 2013-07-16 10:35 琥珀玲珑 阅读(443) 评论(0) 推荐(0)
文件位置标记的定位
摘要:#includeint main(){FILE *fp1,*fp2;fp1=fopen("file1.dat","r"); //打开输入文件fp2=fopen("file2.dat","w"); //打开输出文件while(!feof(fp1)) //feof判断是否到fp1的能结尾putchar(fgetc(fp1)); //从fp1中读入一个字符,并显示在屏幕上putchar(10); //换行功能rewind(fp1); //使文件位置标记返回文件头while(!feof(fp1))fputc(fgetc(f 阅读全文
posted @ 2013-07-13 17:56 琥珀玲珑 阅读(264) 评论(0) 推荐(0)
向文件读写一组数据
摘要:#include#include#define size 10struct student_type{char name[10];int num;int age; char addr[15];}stu[size]; //全局变量stu数组,包含10个学生void save() //存储功能{ FILE *fp;int i;if((fp=fopen("stu.dat","wb"))==NULL) //打开stu.dat文件{ printf("can't open file!\n");exit(0);//return;}for(i 阅读全文
posted @ 2013-07-13 10:07 琥珀玲珑 阅读(220) 评论(0) 推荐(0)
单词排序
摘要:#include#include#includeint main(){FILE *fp;char str[3][10],temp[10]; //定义一个二维数组str和一个临时数组tempint i,j,k,n=3;printf("Enter string:\n");for(i=0;i0)k=j;if(k!=i){strcpy(temp,str[i]);strcpy(str[i],str[k]);strcpy(str[k],temp);}}if((fp=fopen("I:\\string.dat","w"))==NULL) //打开文 阅读全文
posted @ 2013-07-10 18:32 琥珀玲珑 阅读(261) 评论(0) 推荐(0)
将一个文件复制到另外一个文件中
摘要:#include#includeint main(){FILE *in,*out; //定义file指针变量输入in,输出outchar ch,infile[10],outfile[10]; //定义两个字符数组,分别存放in,out文件printf("请输入读入的文件名:");scanf("%s",infile);printf("请输入输出的文件名:");scanf("%s",outfile);if((in=fopen(infile,"r"))==NULL) //以读的方式打开filename 阅读全文
posted @ 2013-07-10 08:32 琥珀玲珑 阅读(275) 评论(0) 推荐(0)
输入一些字符,逐步送入磁盘,以#结束
摘要:#include#includeint main(){FILE *fp;char ch,filename[10];printf("请输入所用的文件名:");scanf("%s",filename);if((fp=fopen(filename,"w"))==NULL) //以读写的方式打开filename文件,并使fp指向此文件{printf("无法打开此文件\n");exit(0);}ch=getchar(); //用于接收最后输入的回车符printf("请输入一个准备存储到磁盘的字符串(“以#结束):& 阅读全文
posted @ 2013-07-10 08:06 琥珀玲珑 阅读(309) 评论(0) 推荐(0)
共同体类型,学生,教师
摘要:#includestruct //声明无名结构体类型{int num; //编名char name[10]; //姓名char sex; //性别char job; //职业union //声明无名共同体类型{int clas; //班级char position[10]; //职务}category; //共同体变量}person[2]; //定义结构体数组,有两个元素int main(){int i;for(i=0;i<2;i++){printf("please enter the data of person:\n");scanf("%d %s %c 阅读全文
posted @ 2013-07-05 13:10 琥珀玲珑 阅读(330) 评论(0) 推荐(0)
五种颜色的球若干个,从中取三个球,三球颜色不同的组合。
摘要:#includeint main(){enum Color{red,yellow,blue,white,black}; //声明枚举类型enum Colorenum Color i,j,k,pri; //定义枚举变量i,j,k,priint n,loop;n=0;for(i=red;i<=black;i++)for(j=red;j<=black;j++)if(i!=j){for(k=red;k<=black;k++)if((k!=i)&&(k!=j)){n++; //符合条件加1 printf("%-4d",n); //输出第几个符合条件的 阅读全文
posted @ 2013-07-05 12:03 琥珀玲珑 阅读(740) 评论(0) 推荐(0)