ITeye博客

c

共 4 篇文章

指针 数组 结构体 练习

#include <stdio.h> #include <malloc.h> #include <stdlib.h> #include <stdbool.h> //简单数组存储 gcc下运行 //J.WANG 2013-6-8 typedef struct Arr{ int * data; //存储数组的第一个元素的地址 int len; //数组的存储长度 int index; //有效元素个数 } ARR; bool init(ARR *p,int n); //初始存储,p要初始对象的地址,n初始的长度 bool append(ARR *p,int val); //添加元素,p添加的对象…

2013-06-08 20:41 · c

结构体,文件操作,指针,简单练习

#include <stdio.h> #include <stdlib.h> #include <malloc.h> #include <string.h> #define SCORES 5 #define S 3 typedef struct { int num; char *name; char sex[2]; float score[SCORES]; float total; } STU; //输入n个学生的信息 void initInfo(STU * st,int n); //保存n个学生文件 void saveAsFile(STU * st,int n); //根据4门功课分数排序…

2013-05-22 23:30 · c · C语言 · 指针 · 结构体

C语言十进制转任意进制

#include <stdio.h> #define M sizeof(unsigned int)*8 //进制转换 int trans(int n,int d,char *str){ char s[16]="0123456789ABCDEF"; int j,i=M; char buf[i+1]; buf[M]='\0'; if(d<2||d>16){ return 0; } while(n!=0){ buf[--i]=s[n%d]; n/=d; } for(j=0;(*(str+j)=buf[i])!='\0';j++,i++); return j; } int main(){ int i…

2013-05-04 19:08 · c

c语言万年历 日历

/* * cal.c * * Created on: 2013-3-11 * Author: J.WANG */ #include <stdlib.h> #include <stdio.h> //三维数组存放日期,每年12月,日历中最多排6行(星期),每星期7天 int days[12][6][7]; //平年,闰年每个月的天数 int ds[2][12] = { { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } }; //标题 char…

2013-03-12 09:48 · c