03 2013 档案
摘要:内部命令:cdexit(bash)中的一个功能外部命令:lsdate(有对应的二进制文件)单独的二进制文件Cd/tmpexitfork()Ls-l>a.cexec()外if(cmd>){Cmd[]=NULL;结束标志Open(a.c);Dup2(fd,1);}内if(cdbash){内部Cdchdir();Exit;return;Continue;}Ls-l|grepA过滤管道:前面命令的输出作为后面命令的输入完善内部命令ls*.a通配符通配符的支持:ls*.c任意一个ls?.c一个Ls[a-z].ca.cb.cc.cd.cApue几部分1,文件操作所有文件2,多进程进程间通讯1,
阅读全文
摘要:多进程阶段练习1myshell#ls2myshell#ls-l3myshell#ls-l-a/dev4myshell#ls-l空格或\t5myshell#ls-l错误处理6myshell#cd/tmp内部命令exit7myshell#ls-l>a.c8myshell#ls-l|grepA输出管道输入Shell人机交互的工具放到指针数组里shell接受命令->解析执行不会结束while死循环接受指令执行结果charbuf[1024];While(1){Printf("myshell#");Gets(buf);gets()可以有空格Printf("%s\n
阅读全文
摘要:If(isdir(dir->name))continue;If(dir->d_name[0]=='.')continue;If(p==NULL)continue;Strrchr:从最后开始找Char*ptr=".mp3".文件个数#include"count_line_file.h"Gcc.c.c同时编译#ifndef#else#endifStat(name,&info);If((S_ISDIR)(info.st_mode))Return1;ElseReturn0;仅仅是一个名字#ifndef#define#endif
阅读全文
摘要:Rmmyhead.cswp异常中断Return;读到文件尾少打一个加一个=号Atoi(argv[1]+1);练习:编写一个函数获取文件一行OpenreadwritecloseLseek();修改文件偏移量,修改哪一段影响下一次读写操作参数1:open()成功返回值参数2:偏移量+10-1[]偏移量+前,-后,0当前参数3:位置SEEK_SET(文件开始)SEEK_CUR(文件当前)SEEK_END(文件末尾)将文件第一个字符打印5次read从上一次开始读Lseek(fd,0,SEEK_SET);文件开始+1第一个Lseek(fd,-1,SEEK_CUR);很有用Open()回到文件开始打开,读
阅读全文
摘要:输入一个字符串,找出第一个出现一次的字符.将字符窗中的用户id打印转为整数并+1打印.Myuseradd"u3:x:502:502::/home/uu3:/bin/bash"数据指头:“1a2b”,数据针尾:"3c4d"有效数据提出来.(有点难)Bzero():地址0的个数,从该地址存n个0,与buf用Charbuf[100];随即值Bzero(buf,sizeof(buf));Structttabc;Bzero(&abc,sizeof(abc));Memset()地址,值,个数放什么都可以Memset(buf,0,sizeof(buf));改写
阅读全文
摘要:Apue函数(linux系统调用(linuxapi))5分钟函数名:功能不需要记参数Intmain(){例如没有复杂算法Open();->opendir();Read();复杂->{Printf(); readdir();Close(); }closedir();}函数实现内核源代码低版本国外操作系统原理操作系统原理Fgets(输入);Fputs(输出)const栈:结束完释放指针->函数为什么要使用函数函数:重复使用同一段代码~c++继承自定义函数:1,函数声明voidfun(void);2,函数调用fun();3,函数的定义(实现):voidfun(void){Print
阅读全文
摘要:Gets(buf);buf[i]for(;buf;)While(buf[i])i++;字符的ASCII值做判断For(;buf[i];);能放在后边空语句For(i=0;buf[i]==buf0[i];i++);空语句Ch=getchar();Gets(buf);For(i=0;buf[i];i++)最后什么条件结束Gets(buf1);For(i=0;buf2[i]=buf1[i];i++)退出条件Return;exit(),_exit();进程StrcpyStrcatFor(i=0;buf1[i];i++)For(j=0;buf1[i]=buf2[j];j++,i++)StrstrGets
阅读全文
摘要:时间下一秒:判断是不是60,是秒数为0,分钟+1判断分钟是不是60,是分钟为0,小时+1判断小时是不是24,是小时为0,日期+1s=s+1if(s==60){S=0;m=m+1;If(m==60){M=0;H++;If(h==24){H=0;}}}核心算法+一秒scanf("%d:%d:%d",&h,&m,&s);While(1){Sleep(1);表}标准C提供的输入输出函数Printf->缓冲区行全零缓冲Fopen->屏幕printf("\n");刷新缓冲区:fflush(NULL);空指针Fopen()堆上Fcl
阅读全文
摘要:程序:a.c->abc文件(二进制)->./.abc时程ps结果结果相同:可执行文件相同gcc-V(版本)直观:程序返回值intmain(intargc,char**argv){Start没有程序的入口数据区;算法;}Scanf("");没有用处.getcharfgetfgetsFile*查看文件elf可执行文件Printf();声明user/include/stdio--库内核使用的变量va_start()函数Printf();函数变参库libcgcca.c-oabc-lc加载库一个默认的函数库gccd.c-oabcfun.c很多.o->lic.so/l
阅读全文
摘要:1. 做什么。文字2. 分析。 思考3. 设计。 伪代码1嵌入式方向。2图形编程:qt(c++) gtk(c)3应用程序:vim ls ps等。Linux c开发4系统:linux(分时); 系统构建(cpu(arm) 内存 硬盘(flash芯片))5驱动程序:硬件6硬件:pcb画图工具,设计硬件难Linux arm嵌入式文件系统 GRUB引导程序 bootloader linux kernel职位:1GUI编程:qt c++(很难) 3 2C,gcc,gdb,makefile,linuxapi(接口)(apue) 4~5 Apue:文件,多进程,多线程,进程间的通信,网络编程 3系统构建 .
阅读全文
摘要:#include <stdio.h>int main(){int i=1,sum=0,s=0;do{sum=i*(i+1)*(i+2);s+=sum;printf("%d*%d*%d+",i,i+1,i+2);i++;}while(i<=7);sum=i*(i+1)*(i+2);s+=sum;printf("%d*%d*%d=%d\n",i,i+1,i+2,s);//getch();return 0;}#include <stdio.h>int main(){ int i,j,k,sum=0,s=0; for (i=1;i&
阅读全文
摘要:#include <stdio.h>#include <stdlib.h>int main(){int n,m,i,num=0;char *p,*q;q=(char *)malloc(10*sizeof(char));p=(char *)malloc(20*sizeof(char));scanf("%d%d",&n,&m);for (i=m;i<n;i++){sprintf(p,"%d",i);sprintf(q,"%d",m);while(*p!='\0'){if(*p=
阅读全文
摘要:#include <stdio.h>int main(){ /*从键盘上输入一些字符,把这些字符送到磁盘上,直到输入#号时*/ FILE *fp; char filename[10],ch; scanf("%s",filename); if((fp=fopen(filename,"w"))==NULL) { printf("can't open the file.\n"); exit(0); } ch=getchar(); ch=getchar(); while(ch!='#') { fputc(c
阅读全文
摘要:#include <stdio.h>int main(){ /*判断一个字符串中子串出现的次数.*/ char str1[100],str2[20],*p,*q; int sum=0; printf("please input two strings.\n"); scanf("%s%s",str1,str2); p=str1;q=str2; while(*p!='\0') { if(*p==*q) { while(*p==*q&&*q!='\0') { p++; q++; } } else p+
阅读全文
摘要://fputc.c#include <stdio.h>int main(){ /*int fputc(int ch,FILE *p);送一个字符到一个流中*/char *p="abcdefgh";while(*p!='\0'){fputc(*p,stdout);p++;}printf("\n");return 0;}
阅读全文
摘要://strcpy.c#include <stdio.h>#include <windows.h>int main(){/*exterm strcpy(char *dest,char *src);将src字符串中的内容复制到dest所指的字符中.返回指向dest字符串的指针.*/char *d="abcdefgh";char p[20]="";system("cls");strcpy(p,d);printf("%s\n",p);return 0;}
阅读全文
摘要:#include <stdio.h>#include <windows.h>int main(){/*strncat的用法extern char *strncat(char *dest,char *src,int n);将src所指字符串的n个字符填加到dest所指的字符串尾部*/char d[20]="abcd";char *p="efgh";system("cls");strncat(d,p,4);printf("%s\n",d);return 0;}
阅读全文
摘要:#include <windodws.h>system("cls");
阅读全文
摘要:filename 必需。规定要打开的文件或 URL。 mode 必需。规定要求到该文件/流的访问类型。可能的值见下表。 include_path 可选。如果也需要在 include_path 中检索文件的话,可以将该参数设为 1 或 TRUE。 context 可选。规定文件句柄的环境。Context 是可以修改流的行为的一套选项。 "r" 只读方式打开,将文件指针指向文件头。 "r+" 读写方式打开,将文件指针指向文件头。 "w" 写入方式打开,将文件指针指向文件头并将文件大小截为零。如果文件不存在则尝试创建之。 "w+&
阅读全文
摘要:#include <stdio.h>#include <dos.h>int main(){ /*getdate()函数的用法*/ struct date d; getdate(&d); //获取DOS日期 printf("the current year is:%d\n",d.da_year);//cprintf和printf用法是不同的 printf("the current day is:%d\n",d.da_day); printf("the current month is:%d\n",d.da
阅读全文
摘要:#include <conio.h>int main(void){ /*gotoxy()的用法*/ //clrscr(); //清除文本模式的窗口 gotoxy(2,1);//在文本窗口中设置光标用(列,行) cprintf("Hello world");//送格式化输出至屏幕 getch(); return 0;}
阅读全文
摘要:#include <stdio.h>int main(){ /*getchar()从输入设备 得到一个字符,这个 字符显示在屏幕上 getch从输入设备得到 一个字符,但是这个 字符不显示在屏幕上*/ printf("%c",getchar()); printf("%c",getch()); return 0;}
阅读全文
摘要:#include <stdio.h>#include <conio.h>#include <stdlib.h>#include <time.h>int main(){ /*时间函数4:猜数字游戏*/ int i,guess; char c; double var; time_t a,b; clock_t start,end; srand(time(NULL)); printf("\ndo you want to play a game.('y'or'n')\n"); loop: while((c
阅读全文
摘要:/*calculate time*/#include <stdio.h>#include <conio.h>#include <time.h>int main(){ /*时间函数举例3*/ clock_t start,end; int i; double var; // 这是怎么回事啊 start=clock(); for (i=0;i<10000;i++) printf("\1\1\1\1\1\1\1\1\1\1\n"); end=clock(); printf("\1:the different time is %6.
阅读全文
摘要:/*calculate time*/#include <stdio.h>#include <conio.h>#include <time.h>int main(){ /*时间函数举例2 在vc 和win-tc 中结果不同*/ time_t start,end; int i; start=time(NULL); for (i=0;i<30000;i++) printf("\1\1\1\1\1\1\1\1\1\1\n"); end=time(NULL); printf("\1:the different time is %6.
阅读全文
摘要:#include <stdio.h>#include <conio.h>#include <time.h>int main(){ /*时间函数举1*/ time_t lt; //define a longint time available lt=time(NULL); //system time and date printf(ctime(<)); //english format output printf(asctime(localtime(<)));//tranfer to tm printf(asctime(gmtime(&
阅读全文
摘要:#include <stdio.h>int main(){ /*打印楼梯同时在楼梯上方打印出两个笑脸*/ int i,j; printf("\1\1\n"); for (i=1;i<11;i++) { for (j=1;j<=i;j++) printf("%c%c",219,219); printf("\n"); } getch(); return 0;}
阅读全文
摘要:#include <stdio.h>int main(){ /*打印出国际象棋棋盘*/ int i,j; for (i=0;i<8;i++) { for (j=0;j<8;j++) { if ((i+j)%2==0) printf("%c",219); else printf(" "); } printf("\n"); } getch(); return 0;}
阅读全文
摘要:#include <stdio.h>int main(){ /*打印9*9乘法口决,i控制行,j控制列*/ int i,j,result; for (i=1;i<10;i++) { for (j=1;j<=i;j++) { result=i*j; printf("%d*%d=%-3d ",j,i,result); } printf("\n"); } getch(); return 0;}
阅读全文
摘要:#include <stdio.h>int main(){ /*很漂亮的案,运行下试试,very beautiful*/ char a=176,b=219; printf("%c%c%c%c%c\n",b,a,a,a,b); printf("%c%c%c%c%c\n",a,b,a,b,a); printf("%c%c%c%c%c\n",a,a,b,a,a); printf("%c%c%c%c%c\n",a,b,a,b,a); printf("%c%c%c%c%c\n",b,a,a,a
阅读全文
摘要:#include <stdio.h>int main(){ /*用*号输出字母C的图案*/ printf("hello C-world\n"); printf(" ****\n"); printf(" **\n"); printf(" **\n"); printf(" ****\n"); getch(); return 0;}
阅读全文
摘要:#include <stdio.h>int main(){ /*输入三个数把这三个数按由小到大的顺序输出*/ int x,y,z,t; scanf("%d %d %d",&x,&y,&z); if (x>y) { t=x; x=y; y=t; } if (x>z) { t=x; x=z; z=t; } if (y>z) { t=y; y=z; z=t; } printf("small to big %d %d %d\n",x,y,z); getch(); return 0;}
阅读全文
摘要:#include <stdio.h>int main(){ /*输入年月日判断这是一年中的第几天.*/ int year,month,day,sum,leap; printf("please input year month day\n"); scanf("%d %d %d",&year,&month,&day); switch(month) { case 1:sum=0;break; case 2:sum=31;break; case 3:sum=59;break; case 4:sum=90;break; case
阅读全文
摘要:#include <stdio.h>#include <math.h>int main(){ /*一个整数,加上100后是一个 完全平方数,再加上168后也是 一个完全平方数,求该数是多少*/ long int i,x,y; for (i=1;i<=100000;i++) { x=sqrt(i+100); y=sqrt(i+268); if(x*x==(i+100)&&y*y==(i+268)) printf("\n%d\n",i); } getch(); return 0;}
阅读全文
摘要:代码中有全角标点符号.
阅读全文
摘要:#include <stdio.h>int main(){ /*企业发放的奖金根据利润提成。 利润(I)低于或等于10万元时, 奖金可提10%;利润高于10万元 ,低于20万元时,低于10万元的 部分按10%提成,高于10万元的 部分,可提成7.5%;20万到40万 之间时,高于20万元的部分,可 提成5%;40万到60万之间时高于 40万元的部分,可提成3%;60万到 100万之间时,高于60万元的部分, 可提成1.5%,高于100万元时,超过 100万元的部分按1%提成,从键盘 输入当月利润I,求应发放奖金总数? 程序分析:请利用数轴来分界, 定位。注意定义时需把奖金定义 成长
阅读全文
摘要:#include <stdio.h>int main(){ /*有1,2,3,4个数,能组成多少 个互不相同且无重复数字的三 位数分别是多少。 程序分析:百位十位个位上的 数字分别是1,2,3,4,先全部排 列出来,再去掉不满足条件的*/ int i,j,k; for (i=1;i<5;i++) for (j=1;j<5;j++) for (k=1;k<5;k++) { if (i!=j&&i!=k&&j!=k) printf("%d%d%d\n",i,j,k); } getch(); return 0;}
阅读全文
摘要:#include <stdio.h>int main(){ /*学习使用按位取反 程序分析:0~=1 1~=0*/ unsigned int a, b; a=3; b=~a; printf("\40:the a's 1 complement(decimal)is %d\n",b); a=~b; printf("\40:the a's 1 complement(hexidecimal)is %d\n",a); getch(); return 0;}
阅读全文
摘要:#include<stdio.h>int main(){ /*取一个整数a从右端开始的4-7位 程序分析:可以这样考虑: 1.先使a右移4位 2.取一个低4全为1,其余为0的数, 可以这样~(~0<<4) 3.两者相& */ unsigned int a,b,c,d; scanf("%d",&a); b=a>>4; c=~(~0<<4); d=b&c; printf("%d\n",d); getch(); return 0;}
阅读全文
摘要:#include <stdio.h>int main(){ /*学习使用^运算符 0^0=0 0^1=1 1^0=1 1^1=0*/ int a, b; a=077; b=a^3; printf("\40:the a^b(decimal)is %d\n",b); b^=7; printf("\40:the a^b(decimal)is %d\n",b); getch(); return 0;}
阅读全文
摘要:#include<stdio.h>int main(){ /*练习使用|运算符 0|0=0 0|1=1 1|0=1 1|1=1*/ int a, b; a=077; b=a|3; printf("\40:the a|b (decimal)is %d\n",b); b|=3; printf("\40:the a|b(decimal)is %d\n",b); getch(); return 0;}
阅读全文
摘要:#include <stdio.h>int main(){ /*练习使用&运算符 0&0=0 0&1=0 1&0=0 1&1=1*/ int a, b; a=077; b=a&3; printf("\40:the a&b(decimal)is %d\n",b); b&=7; printf("\40:the a&b(decimal)is %d\n",b); getch(); return 0;}
阅读全文
摘要:#include <stdio.h>#define M 5int main(){ /*专升本一题:读结果*/ int a[M]={1,2,3,4,5}; int i,j,t; i=0;j=M-1; while(i<=j) { t=*(a+i); *(a+i)=*(a+j); *(a+j)=t; i++;j--; } for (i=0;i<M;i++) { printf("%d",*(a+i)); } printf("\n"); getch(); return 0;}
阅读全文
摘要:#include <stdio.h>int main(){ /*某公司采用公用 电话传递数据,数? 数据是加密的, 加密规则如下:每位数 字都加上5,用它们的和? 除以10的余数替代该数字 ,第一位和第四位交换.*/ int a, i, t, aa[4]; scanf("%d",&a); aa[0]=a%10; aa[1]=a%100/10; aa[2]=a%1000/100; aa[3]=a/1000; for(i=0;i<4;i++) { aa[i]+=5; aa[i]%=10; } for (i=0;i<=3/2;i++) { t=a
阅读全文
摘要:#include <stdio.h>int main(){ /*从键盘读取7个数(1-50)的整数值,每读取一个值打印出该值个数的*号*/ int a,i,n=1; while(n<=7) { do { scanf("%d",&a); }while(a<1||a>50);//每次只读取一个值 for(i=1;i<=a;i++) { printf("*");//打印*号 } n++;//计数 printf("\n"); } getch(); return 0;}
阅读全文
摘要:#include "stdio.h"struct student{ int x; char c;}a;void f1(struct student b);void f2(struct student *b);void main(void){ a.x=3; a.c='a'; f1(a); printf("%d,%c\n", a.x, a.c); f2(&a); printf("%d,%c\n", a.x, a.c);}void f1(struct student b){ b.x=20; b.c='y
阅读全文
摘要:#include <stdio.h>int main(){ //两个字符串的连接程序 char a[100]="abcd"; char b[100]="efgh"; int i=0,j=0; while(a[i]!='\0') i++; while(b[j]!='\0') { a[i++]=b[j++]; } puts(a); // getch(); return 0;}
阅读全文
摘要:#include <stdio.h>int main(){ //判断一个素数能被几个9整除 long int sum=9,num9=9;//数据类型为长整型 int zi,n=1,c9=1; scanf("%d",&zi); while(n!=0) { if(!(sum%zi)) n=0; else { num9=num9*10;//sum9=sum9*10; sum=sum+num9; c9++; } } printf("%ld can be divided by %d\"9\"",sum,c9);//\&quo
阅读全文
摘要:#include <stdio.h>#include <math.h>int main(){/*一个偶数总能表示为两个素数的和*/int a, b, c, d;scanf("%d",&a);if (2==a||4==a)//1,2,3都是素数printf("%d=%d+%d\n",a, a/2, a/2);for (b=3;b<=a/2;b++)//这也会有发现的{for (c=2;c<sqrt(b);c++)//这个部分很容易出错的if (b%c==0)break;if (c>sqrt(b))d=a-b
阅读全文
摘要:#include<stdio.h>int main(){/*求0-7所能组成的奇数的个数*/long sum=4, s=4;int j;for (j=2; j<=8; ++j){printf("\n%ld", sum);if (j<=2)//最高位不能为0s*=7;//s=s*7;elses*=8;//s=s*8;sum+=s;}printf("\nsum=%ld",sum);return 0;}
阅读全文
摘要:#include<stdio.h>int main(){/*八进制转换成十进制*/char *p, s[6];//字符串的类型为charint n;p=s;gets(p);n=0;while(*p!='\0'){n=n*8+*p-'0';//printf("n=%d *p-'0'=%d\n", n, *p-'0');*p++;}printf("%d\n",n);return 0;}
阅读全文
摘要:#include <stdio.h>int output(int number1, int number2, int number3){ printf("809*%ld = 800*%ld + 9*%ld + 1\n",number1, number2, number3); //printf("809*%ld=%ld\n",number1, 809*number1); return 0;}int main(){ /*809*??=800*??+9*??+1,??为两位数,8*??为两位数,9*??为三位数,求??的值及809*??的值*/ i
阅读全文

浙公网安备 33010602011771号