- 博客(49)
- 资源 (8)
- 收藏
- 关注
原创 递归算法的应用
递归算法:是把问题转化为规模缩小了的同类问题的子问题。然后递归调用函数(或过程)来表示问题的解。一个过程(或函数)直接或间接调用自己本身,这种过程(或函数)叫递归过程(或函数).1.斐波那契数列#include int fibonacci(int i){ int ret = -1; if(i<0) //判断是否输入有误 { return ret;
2017-01-30 16:45:10 322
原创 自己封装实现getline()函数
分析getline函数功能。函数需要的参数。需要用到到函数:malloc(),fgetc(),remalloc();#include #include #define maxsize 120 //定义申请大小为120 static ssize_t mygetline(char **lineptr, size_t *n, FILE *stream){ ssize_t cou
2017-01-26 19:13:30 1723 1
原创 读《和你在一起就是全世界》
这本书是一天读完的。作者大柠,第一次听,这本书和两年前读的乔一《我不喜欢这个世界,我只喜欢你》差不多的风格。 封面的一句话“世界很大,人山人海;世界很小,只你共我。with you,with the world.”从校服到婚纱,从情侣到伴侣的一对。故事的开始一个大四一个大二,故事的结束宝宝已经可以打酱油了。从遇上你就是最美好的时光到两个人,一个世界,他们从青涩到成熟,从校园走向社会,从懵懂
2017-01-23 16:22:05 321
原创 栈的实现
栈的定义:栈是限制在表的一端进行插入和删除的线性表。允许插入、删除的这一端称为栈顶,另一个固定端称为栈底。当表中没有元素时称为空栈。栈的操作:1.创建栈2.销毁栈3.清空栈4.进栈5.出栈6.获取栈顶元素7.获取栈的大小栈的实现方式:1.顺序存储实现:利用数组,只对a[0]进行操作 。下面通过复用顺序链表代码实现。2链式栈
2017-01-23 11:49:11 292
原创 双向链表
#include #include #include "DLinkList.h"typedef struct _tag_DLinkList{ DLinkListNode header; DLinkListNode* slider; int length;} TDLinkList;DLinkList* DLinkList_Create() // O(1){
2017-01-22 17:22:59 195
原创 c语言学生通讯系统
#include //标准输入,输出函数#include //常用函数#include //字符串函数#include //文本窗口函数struct record //定义结构体{ char name[20]; //姓名 char phone[12]; ///int char adress[50]; //地
2017-01-21 17:03:36 582
原创 c语言计算器
#includevoid main(){ char ch; float a,b; ch=getchar(); printf("input a,b\n"); scanf("%f,%f",&a,&b); switch(ch) { case '+' :printf ("a+b=%f\n",a+b);break; case '-' :printf
2017-01-21 17:02:11 615
原创 c语言判断一串字符小写字符的个数
#includevoid main(){ int count=0; char c; do { c=getchar(); if(c>='a' && c<='z') count++; } while(c!='\n'); printf("count=%d",count);}
2017-01-21 16:59:38 1278
原创 c语言判断一个数是否为素数
#include#includevoid main(){ int i,j,k,count; for(i=3;i<301;i++) { // k=sqrt((double)i); for(j=2;j<=i/2;j++) if(i%j==0) /*m不是素数退出循环*/ break; if(j>i/2)
2017-01-21 16:49:12 1387 2
原创 c语言简易五子棋的实现
#include #include #include #include #define MAXIMUS 15 //定义棋盘大小int p[MAXIMUS][MAXIMUS];//存储对局信息char buff[MAXIMUS*2+1][MAXIMUS*4+3];//输出缓冲器int Cx,Cy;//当前光标位置int Now;//当前走子的玩家,1代表黑,2代表白int wl
2017-01-21 16:46:59 17966 1
原创 c语言实现万年历
#include #define LMonth 31#define SMonth 30#define VMonth 28// 定义一种新的数据类型 - 枚举型typedef enum { Sun,Mon,Jue,Wed,Thu,Fri,Sat} WEEK;typedef enum { January =1, February, Match, Apirl, May,
2017-01-20 18:05:50 578
原创 MSP430 12864显示
/********************************************************************//DM430开发板控制带字库型12864液晶模块显示测试程序//显示模式为汉字模式,直接将12864插入12864接口即可//注意选择液晶的电源,位于电位器附近,可选5V或3.3V,根据液晶电压进行选择//调试环境:EW430 V5.30//**
2017-01-19 16:42:02 1299
原创 MSP430 IIC通信
#include#define OP_READ 0xa1 //器件地址读#define OP_WRITE 0xa0 //器件地址写#define uchar unsigned char#define uint unsigned int #define SDA_OUT P1DIR |= BIT3#define S
2017-01-19 16:40:08 3397 3
原创 MSP4301602显示Ⅱ
/********************************************************************1602液晶显示********************************************************************/#include #define CPU_F ((double)8000000) #define
2017-01-19 16:38:31 393
原创 MSP4301602显示Ⅰ
/********************************************************************1602液晶显示********************************************************************/#include #define CPU_F ((double)8000000)
2017-01-19 16:37:20 380
原创 关于运算符操作的那些小函数
运算符小程序集合int i=3;(++i)+(++i)+(++i);max=(a>b)?a:b;int i=0,j=0;if( (++i>0) || (++j>0) ){ //打印i,j的值}i=1,2; (i=1),2;int x;int i=3;x=(++i,++i,i+10);与 或 异或与:用于清零某一位&或:|异或: ^左移 右
2017-01-18 09:15:58 170
原创 MSP430按键中断Ⅱ
#includetypedef unsigned char uchar;typedef unsigned int uint;#define keyin (P1IN & 0X0F)#define wei_h P5OUT |= BIT5#define wei_l P5OUT &= BIT5#define duan_l P6OUT &= ~BIT6#define duan_h P6OUT
2017-01-17 18:07:32 545
原创 MSP430按键中断
#includetypedef unsigned char uchar;typedef unsigned int uint;#define keyin (P1IN & 0X0F)#define wei_h P5OUT |= BIT5#define wei_l P5OUT &= BIT5#define duan_l P6OUT &= ~BIT6#define duan_h P6OUT
2017-01-17 18:06:23 1206 3
原创 利用lseek()函数创建一个固定大小的文件
#include #include #include #include #include #include int main(int argc,char ** argv){ int fd; fd = open(argv[1], O_CREAT|O_TRUNC|O_RDWR,S_IRUSR|S_IWUSR); if( fd < 0 ) {
2017-01-17 12:05:03 849
原创 fprintf()的使用
fprintf函数输出在标准输出位置。#include #include int main(){ int i = 150; int j = 100; double k = 3.14159; fprintf(stdout,"i=%d,j=%d,k=%lf\n",i,j,k); exit(0);}
2017-01-16 14:39:49 5894
原创 getpw()函数的使用
#include #include #include #include #define _GNU_SOURCEint main(){ char buf[80]; getpw(0,buf); printf("%s\n",buf); exit(0);}
2017-01-16 14:35:00 581
原创 MSP430数码管的使用Ⅲ
规范代码#includetypedef unsigned char uchar;#define wei_h P5OUT |= BIT5#define wei_l P5OUT &= BIT5#define duan_l P6OUT &= ~BIT6#define duan_h P6OUT |= BIT6uchar table[16] = {0x3f,0x06,0x5b,
2017-01-15 11:25:09 1030 1
原创 MSP430数码管的使用Ⅱ
通过宏定义设置段选位选#includetypedef unsigned char uchar;#define wei_h P5OUT |= BIT5#define wei_l P5OUT &= BIT5#define duan_l P6OUT &= ~BIT6#define duan_h P6OUT |= BIT6uchar table[16] = {0x3f,0x0
2017-01-15 11:18:29 508
原创 MSP430数码管的使用Ⅰ
首先应该了解数码管及其工作原理。了解你使用的是共阴还是共阳数码管,其次了解数码管的段选位选。接下来是一个例程#includetypedef unsigned char uchar;#define wei_h P5OUT |= BIT5#define wei_l P5OUT &= BIT5#define duan_l P6OUT &= ~BIT6#define
2017-01-15 11:15:35 1086
原创 MSP430定时器的使用
通过计算设置周期。#includevoid main( void ){ // Stop watchdog timer to prevent time out reset WDTCTL = WDTPW + WDTHOLD; //WDTCTL = 0X5A80;关狗 CCTL0 = CCIE; //使能CC
2017-01-15 11:05:40 507
原创 MSP430流水灯Ⅱ
//流水灯三种流动方式和四种流动速度#includetypedef unsigned int uint;uint i = 0,j = 0,dir = 0;uint flag = 0,speed = 0;void main( void ){ P1DIR = 0XFF;P1OUT = 0XFF; P2DIR = 0XFF;P2OUT = 0XFF; P3DI
2017-01-15 09:09:06 1248
原创 MSP430流水灯Ⅰ
#includeunsigned char LED;unsigned int table[8] = {BIT0,BIT1,BIT2,BIT3,BIT4,BIT5,BIT6,BIT7};void main( void ){ // Stop watchdog timer to prevent time out reset WDTCTL = WDTPW + WDTHOLD; L
2017-01-15 09:02:09 1260
原创 dup()函数的使用
#include #include #include #include #include #include #define FNAME "/tmp/out"int main(){ int fd;// close(1); fd = open(FNAME,O_WRONLY|O_CREAT|O_TRUNC,0600); if( fd < 0 )
2017-01-14 20:01:19 1988
原创 MSP430锁频环的使用
#includevoid delay(int x){ int i,j; for(i=x;i>0;i--) for(j=112;j>0;j--);}int main( void ){ // Stop watchdog timer to prevent time out reset BCSCTL1 |= DIVA_2; WDTCTL = WDT_ADLY_10
2017-01-14 14:31:13 805
原创 MSP430定时器的使用
#include #define uint unsigned intvoid delay(int x){ int i,j; for(i=x;i>0;i--) for(j=112;j>0;j--);}int main( void ){// uint a; P2DIR = 0XFF; WDTCTL = WDTPW + WDTHOLD;/* BCSCTL1
2017-01-14 14:16:34 593
原创 MSP430看门狗的使用
#includevoid main(){ WDTCTL = WDT_ADLY_1000; //设置为1000ms(只有8种模式) IE1 = WDTIE; P2DIR |= BIT0; _BIS_SR(LPM3_bits + GIE); }#pragma vector = WDT_VECTOR__interrupt void
2017-01-13 22:33:28 811
原创 MSP430点亮led小灯
#includevoid delay(int x){ int i,j; for(i=x;i>0;i--) for(j=112;j>0;j--);}int main( void ){ // Stop watchdog timer to prevent time out reset WDTCTL = WDTPW + WDTHOLD; //WDTPW 高八位 WDTHOLD置1 关闭看门狗 //P2DI
2017-01-13 22:30:56 6231
原创 open() close() 函数的使用
#include #include #include #include #include #define BUFFSIZE 1024int main(int argc,char** argv){ int sfd,dfd; char buf[BUFFSIZE]; int len,ret,pos; if( argc < 3 ) {
2017-01-13 22:17:56 856
原创 getline()函数的实现
#include #include #include int main(int argc,char** argv){ FILE* fp; char* linebuf; size_t linesize; if( argc < 2 ) { fprintf(stderr,"Usage...\n"); exit(1);
2017-01-13 20:22:12 539
原创 fgetc() Ⅱ
#include #include int main(int argc,char** argv){ FILE *fps,*fpd; int ch; if( argc < 3 ) { fprintf(stderr,"Usage: %s, \n",argv[0]); } fps = fopen(argv[1],"r");
2017-01-12 19:42:42 226
原创 fgets()函数
使用fgets()函数获取文件,并写入固定文件#include #include #define BUFFSIZE 1024int main(int argc,char** argv){ FILE *fps,*fpd; char buff[BUFFSIZE]; if( argc < 3 ) { fprintf(stderr,
2017-01-12 19:36:12 280
原创 fgetc()函数的简单使用
使用fgetc()函数读取文件大小#include #include int main(int argc,char** argv){ FILE *fp; int count; if( argc < 2 ) { fprintf(stderr,"Usage...\n"); } fp = fopen(argv[0],"r")
2017-01-12 19:29:21 1333 1
原创 循环链表
通过对单链表进行改进实现循环链表解决约瑟夫环问题。对其表头元素进行处理成环。main.c#include #include #include "CircleList.h"struct Value{ CircleListNode header; int v;};/* run this program using the console pauser or add
2017-01-11 18:03:28 198
原创 静态链表的清空
void StaticList_Clear(StaticList* list){ TStaticList* sList = (TStaticList*)list; int i = 0; if( sList != NULL) { sList->header.data = 0; sList->header.next = 0; for(i=1;icapacity;i++
2017-01-11 08:57:01 292
原创 静态链表的创建
StaticList* StaticList_Create(int capacity){ TStaticList* ret = NULL; int i = 0; if(capacity >= 0) { ret = (TStaticList*)malloc(sizeof(TStaticList) + sizeof(TStaticListNode) * (capacity + 1))
2017-01-11 08:54:55 312
STM32F10x_lib.h
2017-04-10
MSP430F149数据手册
2016-05-10
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人