随笔分类 -  C语言

摘要:int find(int n,int a[],int l){int low=0;int high=l-1;int middle=0;while(low<high){middle=(low+high)>>1;if(n==a[middle]){printf("%d,%d",n,middle);retur 阅读全文
posted @ 2016-06-13 09:50 ocean2015 阅读(22436) 评论(1) 推荐(1)
摘要:程序分为:代码区、数据区、bss区、堆区、栈区。平时常用区分的是代码区、堆区、栈区。下面加上例子区分一下。 程序分为:代码区、数据区、bss区、堆区、栈区。平时常用区分的是代码区、堆区、栈区。下面加上例子区分一下。 3 代码区顾名思义就是存放代码的,里面的内容是不可以修改的。例如你定义了一个变量ch 阅读全文
posted @ 2016-05-21 15:04 ocean2015 阅读(2641) 评论(0) 推荐(0)
摘要:结构体的数据类型的有点我们就不啰嗦了,直接来看相同数据结构体的几种书写的格式吧。 格式一: [cpp] view plain copy 01.struct tagPhone 02.{ 03. char A; 04. int B; 05. short C; 06.}Phone; [cpp] view 阅读全文
posted @ 2016-05-21 13:59 ocean2015 阅读(860) 评论(0) 推荐(0)
摘要:一个程序本质上都是由 BSS 段、data段、text段三个组成的。这样的概念在当前的计算机程序设计中是很重要的一个基本概念,而且在嵌入式系统的设计中也非常重要,牵涉到嵌入式系统运行时的内存大小分配,存储单元占用空间大小的问题。 BSS段:在采用段式内存管理的架构中,BSS段(bss segment 阅读全文
posted @ 2016-05-21 13:27 ocean2015 阅读(335) 评论(0) 推荐(0)
摘要:在我们的编译器,我用的是ADS 开发平台,现在RTC模块编程时,2410作为上位机,如下代码: n = rBCDDATE;if(n==1) time->day =0x31 ; 波斯历的日期与我们的不同,他们是123456月31天,789 10 11 月30天,12月29或28天天,因此与我们的RTC 阅读全文
posted @ 2016-05-11 17:33 ocean2015 阅读(248) 评论(0) 推荐(0)
摘要:int main(void) { char a[50];int i=0;char *j;gets(a);//输入字符串j=a;while(*j!='\0'){j++;//指针指向下一个数组字符i++;}printf("字符串为%s,字符串的长度为%d\n\n\n",a,i); return 0;} 阅读全文
posted @ 2016-03-15 16:36 ocean2015 阅读(1233) 评论(0) 推荐(0)
摘要:int main(void) { FILE *fp; char ch,filename[10]; scanf("%s",filename); if((fp=fopen(filename,"w"))==NULL) { printf("cannot open file\n"); exit(0); } c 阅读全文
posted @ 2016-03-15 14:22 ocean2015 阅读(279) 评论(0) 推荐(0)
摘要:int main(void) { char s[70]; FILE *fp; fp=fopen("123.txt","r"); if((fp=fopen("123.txt","w"))==NULL) //if 语句就是创建了一个空的.txt文件 { printf("Open the file fai 阅读全文
posted @ 2016-03-15 14:01 ocean2015 阅读(841) 评论(0) 推荐(0)
摘要:main(){   int i=8;   printf("%d %d %d %d %d %d ",++i,--i,i++,i--,-i++,-i--); } 运行结果 8 7 7 8 -7 -8 例2 main(){   int i=8;   printf("%d ",++i);   printf( 阅读全文
posted @ 2016-03-15 09:43 ocean2015 阅读(283) 评论(0) 推荐(0)
摘要:int main(void){ char ch; char str[80];   printf("Input a string: ");    //先输入字符串 gets(str);//get()   put()   这两个函数并列使用,前者就是从案件获取按键值,  后者是显示输出 puts(str 阅读全文
posted @ 2016-03-15 09:42 ocean2015 阅读(228) 评论(0) 推荐(0)
摘要:main(){ FILE *fp; char str[100],filename[10]; int i=0;if((fp=fopen("test","w"))==NULL) //{printf("cnnot open file\n");exit(0); }printf("lease input a 阅读全文
posted @ 2016-03-14 16:33 ocean2015 阅读(331) 评论(0) 推荐(0)
摘要://计算机器运行时间 long i = 10000000L;clock_t start, finish;double duration;//测量一个事件持续的时间printf( "Time to do %ld empty loops is ", i) ;start = clock();while( 阅读全文
posted @ 2016-03-12 11:54 ocean2015 阅读(211) 评论(0) 推荐(0)
摘要:char c; clock_t start,end; time_t a,b; double var; int i,guess; srand(time(NULL));loop: printf("DO YOU WANT TO PLAY IT .('y' or 'n')\n"); while((c=get 阅读全文
posted @ 2016-03-12 11:53 ocean2015 阅读(314) 评论(0) 推荐(0)
摘要:#include <stdio.h> #include <stdlib.h> main() { unsigned int seed; /*申明初始化器的种子,注意是unsigned int 型的*/int k;printf("Enter a positive integer seed value: 阅读全文
posted @ 2016-03-11 16:18 ocean2015 阅读(252) 评论(0) 推荐(0)
摘要:#include<stdio.h>#include<malloc.h>#include<conio.h>#include<stdlib.h>#include "math.h"#include"time.h"#define NULL 0 main() { float a;srand(123456); 阅读全文
posted @ 2016-03-11 16:13 ocean2015 阅读(145) 评论(0) 推荐(0)
摘要:#include<stdio.h>#include<malloc.h>#include<conio.h>#include<stdlib.h>#include "math.h"#define NULL 0#define LEN sizeof(struct cle) struct cle { int n 阅读全文
posted @ 2016-03-11 10:36 ocean2015 阅读(265) 评论(0) 推荐(0)
摘要:#include <stdio.h> #include <malloc.h>#include<graphics.h>#include<conio.h> #define LEN sizeof(struct student)#include "math.h"#define PI 3.1415926 vo 阅读全文
posted @ 2016-02-27 16:29 ocean2015 阅读(371) 评论(0) 推荐(0)
摘要:举一个简单的例子,如果有按键,就输出相关按键。否则,输出“.”。每隔 100 毫秒输出一次。按 ESC 退出。注:ESC 的 ASCII 码是 27。 #include <stdio.h> #include <malloc.h>#include<graphics.h>#include<conio.h 阅读全文
posted @ 2016-02-27 14:28 ocean2015 阅读(2464) 评论(0) 推荐(0)
摘要:#include <stdio.h> #include <malloc.h>#include<graphics.h> #define LEN sizeof(struct student)#include "math.h"#define PI 3.1415926 void main() {initgr 阅读全文
posted @ 2016-02-27 14:19 ocean2015 阅读(3081) 评论(0) 推荐(0)
摘要:#include <stdio.h>#include <malloc.h>#define LEN sizeof(struct student) /*----------------数据定义----------------------*/ //定义一个学生信息的结构体,包括学号,姓名和结构体类型的指针 阅读全文
posted @ 2016-01-30 13:41 ocean2015 阅读(294) 评论(0) 推荐(0)