2018年6月28日

摘要: 1 //编写个人通讯录管理系统,实现以下功能 2 //1.管理系统提供菜单 3 //2.将通讯录存入文件中,并且命名为PersonInfo.txt 4 //3.管理系统将执行以下操作 5 //(1)查看通讯录的所有信息 6 //(2)输入要查找的姓名,查找通讯录,如果找到则显示相关信息 7 //(3 阅读全文
posted @ 2018-06-28 17:47 孙悟空son_ku_kong 阅读(283) 评论(0) 推荐(0)
摘要: 1 //ferror函数的作用是检查文件中是否有错误,如果有错,则返回非0,否则返回0 2 //ferror(文件指针) 3 #include 4 #include 5 int main(){ 6 FILE *fp; 7 if((fp=fopen("file_data.txt","r"))==NULL){ 8 printf("打开文件失败\n");... 阅读全文
posted @ 2018-06-28 17:46 孙悟空son_ku_kong 阅读(192) 评论(0) 推荐(0)
摘要: 1 //feof函数的作用是判断文件指针是否在文件末尾,如果在文件末尾,返回非0,否则返回0 2 //feof(文件指针) 3 #include<stdio.h> 4 #include<stdlib.h> 5 int main(){ 6 FILE *fp; 7 char c; 8 if((fp=fo 阅读全文
posted @ 2018-06-28 17:45 孙悟空son_ku_kong 阅读(140) 评论(0) 推荐(0)
摘要: 1 //ftell函数的作用是返回文件位置指针的位置,给出当前位置指针相对于文件头的字节数 2 //返回值为long,当函数调用出错时,函数返回-1L 3 //ftell(文件指针) 4 #include 5 #include 6 int main(){ 7 FILE *fp; 8 long i; 9 if((fp=fopen("file_data.tx... 阅读全文
posted @ 2018-06-28 17:44 孙悟空son_ku_kong 阅读(178) 评论(0) 推荐(0)
摘要: 1 //fseek函数的作用是将文件的位置指针移到指定位置 2 //fseek(文件指针,位移量,起始点) 3 #include 4 #include 5 int main(){ 6 FILE *fp; 7 char s[]="abcdefghijklmnopqrstuvwxyz"; 8 char c; 9 if((fp=fopen("file_... 阅读全文
posted @ 2018-06-28 17:43 孙悟空son_ku_kong 阅读(159) 评论(0) 推荐(0)
摘要: 1 //rewind函数的作用是使位置指针重新返回指定文件的开头 2 #include 3 #include 4 int main(){ 5 FILE *fp; 6 char s[]="abcdefghijklmnopqrstuvwxyz"; 7 char c; 8 if((fp=fopen("file_data.txt","w+"))==NULL... 阅读全文
posted @ 2018-06-28 17:42 孙悟空son_ku_kong 阅读(202) 评论(0) 推荐(0)
摘要: 1 //fread函数的作用是从指定文件中读入指定长度的数据块 2 //fread(buffer,size,count,文件指针) 3 #include 4 #include 5 int main(){ 6 struct Book_Type{ 7 char name[10]; 8 int price; 9 char aut... 阅读全文
posted @ 2018-06-28 17:41 孙悟空son_ku_kong 阅读(138) 评论(0) 推荐(0)
摘要: 1 //fwrite函数的作用是将指定长的数据写入文件中 2 //fwrite(fp,size,count,文件指针) 3 #include<stdio.h> 4 #include<stdlib.h> 5 int main(){ 6 struct Book_Type{ 7 char name[10] 阅读全文
posted @ 2018-06-28 17:38 孙悟空son_ku_kong 阅读(132) 评论(0) 推荐(0)
摘要: 1 //fscanf函数从指定的文件中按指定格式读入数据,与scanf函数作用类似,scanf从键盘输入,fscanf从文件输入 2 #include 3 #include 4 int main(){ 5 FILE *fp; 6 int i,j; 7 double m,n; 8 char s1[100],s2[100],s3[100],s4[100... 阅读全文
posted @ 2018-06-28 17:33 孙悟空son_ku_kong 阅读(144) 评论(0) 推荐(0)
摘要: 1 //fprintf函数将数据按指定格式写入指定文件中,与printf函数相似 2 //形式为 fprintf(文件指针,格式字符串,输出列表) 3 #include 4 #include 5 int main(){ 6 FILE *fp; 7 int i=10,j=12; 8 double m=1.5,n=2.345; 9 char s[]=... 阅读全文
posted @ 2018-06-28 17:24 孙悟空son_ku_kong 阅读(165) 评论(0) 推荐(0)
摘要: 1 //fgets函数的作用是从指定文件中读取n-1个字符,然后在最后添加一个'\0'字符作为字符串结束的标志 2 //如果在读完n-1个字符之前遇到一个换行符或者EOF,则读入结束 3 #include 4 #include 5 int main(){ 6 FILE *fp; 7 char str[100]; 8 int n; 9 if( (f... 阅读全文
posted @ 2018-06-28 17:23 孙悟空son_ku_kong 阅读(182) 评论(0) 推荐(0)
摘要: 1 //fputs函数是把字符串写入指定文件中 2 #include 3 #include 4 int main(){ 5 FILE *fp; 6 char str[20]; 7 if((fp=fopen("file_data.txt","w"))==NULL ){ 8 printf("打开文件失败\n"); 9 exit... 阅读全文
posted @ 2018-06-28 17:22 孙悟空son_ku_kong 阅读(120) 评论(0) 推荐(0)
摘要: 1 //fgetc函数 2 //fgetc函数的作用是从指定的文件读入一个字符 3 #include 4 #include 5 int main(){ 6 FILE *fp; 7 char ch; 8 if( (fp=fopen("file_data.txt","r"))==NULL ){ 9 printf("打开文件失败\n"); 10... 阅读全文
posted @ 2018-06-28 17:14 孙悟空son_ku_kong 阅读(181) 评论(0) 推荐(0)
摘要: 1 //fputc函数 2 //将一个字符写进一个文件中 3 #include 4 #include 5 int main(){ 6 FILE *fp; 7 char ch; 8 if( (fp=fopen("file_data.txt","w"))==NULL ){ 9 printf("打开文件失败\n"); 10 ... 阅读全文
posted @ 2018-06-28 17:13 孙悟空son_ku_kong 阅读(119) 评论(0) 推荐(0)
摘要: 1 //typedef应用举例 2 #include 3 typedef int INTEGER; 4 typedef struct{ 5 int year; 6 int month; 7 int day; 8 }DATE; 9 10 typedef int COUNT[10]; 11 12 int main(){ 13 INTEGER i;... 阅读全文
posted @ 2018-06-28 17:08 孙悟空son_ku_kong 阅读(139) 评论(0) 推荐(0)
摘要: 1 //枚举 2 //1.枚举值对应的整数值默认情况从0开始,可以在枚举类型声明中自定义 3 //2.枚举值不是字符串,不能用printf("%s",a);输出 4 //3.不用枚举也能实现此程序,但是用枚举类型更加直观 5 #include 6 enum weekday{sun=7,mon=1,tue,wed,thu,fri,sat}; 7 int main(){ 8 ... 阅读全文
posted @ 2018-06-28 17:03 孙悟空son_ku_kong 阅读(144) 评论(0) 推荐(0)
摘要: 1 //链表的学习 2 #include 3 #include 4 #define LEN sizeof(struct student) 5 struct student{ 6 int num; 7 float score; 8 struct student *next; 9 }; 10 int n;//这个是链表节点的个数 11 ... 阅读全文
posted @ 2018-06-28 11:38 孙悟空son_ku_kong 阅读(158) 评论(0) 推荐(0)
摘要: //指向指针的结构体 #include struct student{ int num; char name[20]; }student1={1001,"xiaoming"}; int main(){ struct student *p; p=&student1; printf("学生的号数\t学生的名字\t\n"); printf("%d\t%... 阅读全文
posted @ 2018-06-28 11:33 孙悟空son_ku_kong 阅读(125) 评论(0) 推荐(0)
摘要: 1 //用指向指针的指针输出若干字符串 2 #include 3 int main(){ 4 char *name[]={"Basic","Visual Basic","C","Visual C++","Pascal","Delphi"}; 5 char **p; 6 p=name; 7 for(int i=0;i<6;i++){ 8 ... 阅读全文
posted @ 2018-06-28 11:30 孙悟空son_ku_kong 阅读(121) 评论(0) 推荐(0)
摘要: 1 //输入一个1-7的整数,输出对应的星期名,通过调用指针函数实现 2 #include 3 char name[8][20]={"Illegal day","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"}; 4 char *day_name(int n){ 5 if(n7){ 6... 阅读全文
posted @ 2018-06-28 11:29 孙悟空son_ku_kong 阅读(162) 评论(0) 推荐(0)
摘要: 1 #include 2 int max(int x,int y){ 3 if(x>y){ 4 return x; 5 } 6 return y; 7 } 8 9 int min(int x,int y){ 10 if(x<y){ 11 return x; 12 } 13 return y; 14... 阅读全文
posted @ 2018-06-28 11:28 孙悟空son_ku_kong 阅读(160) 评论(0) 推荐(0)
摘要: 1 //用字符串指针作为函数参数,试下字符串的复制 2 #include 3 void cpystr(char *pss,char *pds){ 4 while( (*pds=*pss)!='\0' ){ 5 pss++; 6 pds++; 7 } 8 } 9 10 int main(){ 11 char *pss="... 阅读全文
posted @ 2018-06-28 11:27 孙悟空son_ku_kong 阅读(119) 评论(0) 推荐(0)
摘要: 1 //输出字符串中第n个字符后的所有字符 2 #include 3 int main(){ 4 int n=10; 5 char *str="This is a book"; 6 str=str+n; 7 printf("%s\n",str); 8 return 0; 9 } 阅读全文
posted @ 2018-06-28 11:26 孙悟空son_ku_kong 阅读(81) 评论(0) 推荐(0)
摘要: 1 //利用指针的方式输出二位数组的值 2 #include 3 int main(){ 4 int arr[3][4]={ 5 {0,1,2,3}, 6 {4,5,6,7}, 7 {8,9,10,11} 8 }; 9 int (*p)[4]; 10 p=arr; 11 for(int i=... 阅读全文
posted @ 2018-06-28 11:25 孙悟空son_ku_kong 阅读(110) 评论(0) 推荐(0)
摘要: 1 //使用指针法,利用数组名计算地址引用数字元素 2 #include 3 int main(){ 4 int a[10]; 5 for(int i=0;i<10;i++){ 6 *(a+i)=i; 7 } 8 for(int j=0;j<10;j++){ 9 printf("%4d",*(a+j)); 10 ... 阅读全文
posted @ 2018-06-28 10:56 孙悟空son_ku_kong 阅读(102) 评论(0) 推荐(0)
摘要: 1 //编写用指针变量做参数的函数,将输入的两个整数按从大到小顺序输出 2 #include 3 void swap(int *p1,int *p2){ 4 int temp; 5 temp=*p1; 6 *p1=*p2; 7 *p2=temp; 8 } 9 int main(){ 10 int a,b; 11 int *p1,*... 阅读全文
posted @ 2018-06-28 10:55 孙悟空son_ku_kong 阅读(122) 评论(0) 推荐(0)
摘要: 1 //用指针,输入整数a和b,按从大到小的顺序输出a和b 2 #include 3 int main(){ 4 int *p1,*p2,*p,a,b; 5 printf("请输入两个数字\n"); 6 scanf("%d %d",&a,&b); 7 printf("%d %d\n",a,b); 8 p1=&a; 9 p2=&b;... 阅读全文
posted @ 2018-06-28 10:53 孙悟空son_ku_kong 阅读(114) 评论(0) 推荐(0)
摘要: 下面是文件file.cpp的源代码 下面是文件main.cpp的源代码 阅读全文
posted @ 2018-06-28 10:52 孙悟空son_ku_kong 阅读(114) 评论(0) 推荐(0)
摘要: 1 //static的用法 2 #include 3 void f(int a){ 4 static int b=2; 5 b=a+b; 6 printf("a=%d,b=%d\n",a,b); 7 } 8 9 int main(){ 10 int a=1,i; 11 for(i=1;i<=3;i++){ 12 f(a)... 阅读全文
posted @ 2018-06-28 10:50 孙悟空son_ku_kong 阅读(97) 评论(0) 推荐(0)
摘要: 1 //利用递归求!n 2 #include 3 double fact(int n){ 4 double s; 5 if(n==0 || n==1){ 6 s=1; 7 }else{ 8 s=n*fact(n-1); 9 } 10 return s; 11 } 12 13 int main(){ 14 ... 阅读全文
posted @ 2018-06-28 10:49 孙悟空son_ku_kong 阅读(110) 评论(0) 推荐(0)
摘要: 1 //输入N个字符,查找最大的字符串 2 #include 3 #include 4 int main(){ 5 char s[6][100]; 6 printf("请输入6个字符串\n"); 7 for(int j=0;j<6;j++){ 8 gets(s[j]); 9 } 10 int max=0; 11 f... 阅读全文
posted @ 2018-06-28 10:48 孙悟空son_ku_kong 阅读(110) 评论(0) 推荐(0)
摘要: 1 //统计字符串中的英文单词的数目 2 #include 3 #include 4 int main(){ 5 char s[100]; 6 printf("请输入字符串\n"); 7 gets(s); 8 int i=0,word=0,num=0; 9 for(;s[i]!='\0';i++){ 10 if(s[i]=... 阅读全文
posted @ 2018-06-28 10:46 孙悟空son_ku_kong 阅读(93) 评论(0) 推荐(0)
摘要: 1 //判断回文 2 #include 3 #include 4 int main(){ 5 char s1[100]; 6 printf("请输入字符串\n"); 7 gets(s1); 8 int n=0; 9 for(;s1[n]!='\0';n++){ 10 11 } 12 n--; 13 int fla... 阅读全文
posted @ 2018-06-28 10:45 孙悟空son_ku_kong 阅读(125) 评论(0) 推荐(0)
摘要: 1 //比较两个字符串 2 #include 3 #include 4 int main(){ 5 char s1[100],s2[100]; 6 int i; 7 printf("请输入字符串1\n"); 8 gets(s1); 9 printf("请输入字符串2\n"); 10 gets(s2); 11 if(strc... 阅读全文
posted @ 2018-06-28 10:44 孙悟空son_ku_kong 阅读(134) 评论(0) 推荐(0)

导航