




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、学习必备欢迎下载100 个产品销售记录排序(此类共10 题)code: /* 已知在文件in.dat 中存有100 个产品销售记录, 每个产品销售记录由产品代码dm(字符型4 位), 产品名称 mc(字符型 10 位), 单价 dj(整型 ), 数量 sl(整型 ), 金额 je(长整型 )五部分组成。其中 :金额 =单价 * 数量计算得出。函数readdat( )读取这 100 个销售记录并存入结构数组sell 中。请编制函数sortdat( ), 其功能要求 :按金额从小到大进行排列, 若金额相等 , 则按产品代码从小到大进行排列, 最终排列结果仍存入结构数组sell 中。最后main(
2、) 函数调用函数writedat() 把结果输出到文件out1.da t 中。注意 : 部分源程序存放在prog1.c 中。请勿改动主函数main( )、读数据函数readdat()和输出数据函数 writedat() 的内容。*/ #include #include #include #include #include #define max 100 typedef struct char dm5 ; /* 产品代码*/ char mc11 ; /* 产品名称*/ int dj ; /* 单价*/ int sl ; /* 数量*/ long je ; /* 金额*/ pro ; pro se
3、llmax ; void readdat() ; void writedat() ; void sortdat() /*/ int i,j,k; pro tt; for(i=0; i max-1; i+) k=i; for(j=i+1; j sellj.je)|(sellk.je=sellj.je)&(strcmp(sellk.dm, sellj.dm)0) k=j; if(k!=i) tt=sellk; sellk=selli; selli=tt; /*/ void main() memset(sell, 0, sizeof(sell) ; 精品学习资料 可选择p d f - - -
4、 - - - - - - - - - - - 第 1 页,共 44 页 - - - - - - - - -学习必备欢迎下载readdat() ; sortdat() ; writedat() ; void readdat() file *fp ; char str80, ch11 ; int i ; fp = fopen(in.dat, r) ; for(i = 0 ; i 100 ; i+) fgets(str, 80, fp) ; memcpy(selli.dm, str, 4) ; memcpy(selli.mc, str + 4, 10) ; memcpy(ch, str + 14,
5、4) ; ch4 = 0 ; selli.dj = atoi(ch) ; memcpy(ch, str + 18, 5) ; ch5 = 0 ; selli.sl = atoi(ch) ; selli.je = (long)selli.dj * selli.sl ; fclose(fp) ; void writedat() file *fp ; int i ; fp = fopen(out1.dat, w) ; for(i = 0 ; i sellj.je| (sellk.je=sellj.je) & (strcmp(sellk.dm, sellj.dm) 0) 之三排序要求:按金额从
6、大到小进行排列, 若金额相等 , 则按产品代码从小到大精品学习资料 可选择p d f - - - - - - - - - - - - - - 第 2 页,共 44 页 - - - - - - - - -学习必备欢迎下载进行排列相应语句:if(sellk.je 0) 之四排序要求:按金额从大到小进行排列, 若金额相等 , 则按产品代码从大到小进行排列相应语句:if(sellk.je sellj.je)|(sellk.je=sellj.je)&(strcmp(sellk.dm,sellj.dm)0)|(strcmp(sellk.mc,sellj.mc)=0)&(sellk.jese
7、llj.je) 之六排序要求:按产品名称从小到大进行排列, 若产品名称相同, 则按金额从大到小进行排列相应语句:if(strcmp(selli.mc, sellj.mc)0 | (strcmp(selli.mc, sellj.mc)=0)&(selli.je sellj.je) 之七排序要求:按产品名称从大到小进行排列, 若产品名称相同, 则按金额从小到大进行排列相应语句:if(strcmp(sellk.mc, sellj.mc) sellj.je) 之八排序要求:按产品名称从大到小进行排列, 若产品名称相同, 则按金额从大到小进行排列相应语句:if(strcmp(sellk.mc,
8、sellj.mc) 0)| (strcmp(sellk.mc, sellj.mc)=0)&(sellk.je 0)|(strcmp(sellk.dm,sellj.dm)=0)&(sellk.jesellj.je code: /* 已知在文件in.dat 中存有100 个产品销售记录, 每个产品销售记录由产品代码dm(字符型4 位), 产品名称 mc(字符型 10 位), 单价 dj(整型 ), 数量 sl(整型 ), 金额 je(长整型 )五部分组成。其中 : 金额 =单价 *数量计算得出。函数readdat( )读取这100 个销售记录并存入结构数组sell 中。请编制函数s
9、ortdat( ), 其功能要求 :按产品代码从大到小进行排列, 若产品代码相同, 则按金额从大到小进行排列, 最终排列结果仍存入结构数组sell 中。最后 main()函数调用函数writedat() 把结果输出到文件 out10.dat 中。注意 : 部分源程序存放在prog1.c 中。请勿改动主函数main( ) 、 读数据函数readdat()和输出数据函数writedat() 的内容。*/ #include #include #include #include #include #define max 100 typedef struct char dm5 ; /* 产品代码*/ c
10、har mc11 ; /* 产品名称*/ int dj ; /* 单价*/ int sl ; /* 数量*/ long je ; /* 金额*/ pro ; pro sellmax ; void readdat() ; void writedat() ; void sortdat() /*/ int i,j; pro tt; for(i=0; i max-1; i+) for(j=i+1; j max; j+) if(strcmp(selli.dm, sellj.dm) 0) tt=selli; selli=sellj; sellj=tt; if(strcmp(selli.dm, sellj.
11、dm)=0)&(selli.je sellj.je) tt=selli; selli=sellj; sellj=tt; /*/ 精品学习资料 可选择p d f - - - - - - - - - - - - - - 第 4 页,共 44 页 - - - - - - - - -学习必备欢迎下载void main() memset(sell, 0, sizeof(sell) ; readdat() ; sortdat() ; writedat() ; void readdat() file *fp ; char str80, ch11 ; int i ; fp = fopen(in.dat
12、, r) ; for(i = 0 ; i 100 ; i+) fgets(str, 80, fp) ; memcpy(selli.dm, str, 4) ; memcpy(selli.mc, str + 4, 10) ; memcpy(ch, str + 14, 4) ; ch4 = 0 ; selli.dj = atoi(ch) ; memcpy(ch, str + 18, 5) ; ch5 = 0 ; selli.sl = atoi(ch) ; selli.je = (long)selli.dj * selli.sl ; fclose(fp) ; void writedat() file
13、*fp ; int i ; fp = fopen(out10.dat, w) ; for(i = 0 ; i 0, 则该数满足条件存入数组b 中, 且个数 cnt=cnt+1 。8129, 9-8-1-20, 则该数不满足条件忽略。注意 : 部分源程序存在文件prog1.c 文件中。程序中已定义数组: a300, b300, 已定义变量 : cnt 请勿改动数据文件in.da t 中的任何数据、主函数main()、读函数 readdat()和写函数 writedat() 的内容。*/ #include int a300, b300, cnt=0 ; jsvalue() /*/ int i,j,
14、k,t; for(i=0; i 0) bcnt+=ai; for(i=0; i cnt-1; i+) k=i; for(j=i+1; j cnt; j+) if(bk bj) k=j; if(k!=i) t=bk; bk=bi; bi=t; /*/ main() int i ; readdat() ; jsvalue() ; writedat() ; printf(cnt=%dn, cnt) ; for(i = 0 ; i cnt ; i+) printf(b%d=%dn, i, bi) ; readdat() file *fp ; int i ; fp = fopen(in.dat,r) ;
15、 for(i = 0 ; i 300 ; i+) fscanf(fp, %d, &ai) ; fclose(fp) ; writedat() file *fp ; int i ; fp = fopen(out.dat,w) ; 精品学习资料 可选择p d f - - - - - - - - - - - - - - 第 6 页,共 44 页 - - - - - - - - -学习必备欢迎下载fprintf(fp, %dn, cnt) ; for(i = 0 ; i 0, 则该数满足条件计算平均值pjz1, 且个数 cnt=cnt+1 。9812, 9-8-1-20, 则该数不满足条件计算
16、平均值pjz2。注意 : 部分源程序存在文件prog1.c 文件中。程序中已定义数组: a300, 已定义变量 : cnt,pjz1,pjz2 请勿改动数据文件in.da t 中的任何数据、主函数main()、读函数 readdat()和写函数 writedat() 的内容。*/ #include int a300, cnt=0 ; double pjz1=0.0, pjz2=0.0 ; jsvalue() /*/ int i; for(i=0; i 0) cnt+; pjz1+=ai; else pjz2+=ai; if(cnt) pjz1/=cnt; if(cnt300) pjz2/=30
17、0-cnt; /*/ main() int i ; readdat() ; jsvalue() ; writedat() ; printf(cnt=%dn满足条件的平均值pzj1=%7.2lfn 不满足条件的平均值pzj2=%7.2lfn, cnt,pjz1,pjz2); 精品学习资料 可选择p d f - - - - - - - - - - - - - - 第 9 页,共 44 页 - - - - - - - - -学习必备欢迎下载readdat() file *fp ; int i ; fp = fopen(in.dat,r) ; for(i = 0 ; i cd, ab 必须是偶数且能被
18、5 整除, cd 必须是奇数 ,同时两个新数的十位数字均不为零,则将满足此条件的四位数按从大到小的顺序存入数组b 中, 并要计算满足上述条件的四位数的个数cnt。最后main()函数调用写函数writedat( ) 把结果 cnt 以及数组b 中符合条件的四位数输出到out.da t 文件中。注意 : 部分源程序存在文件prog1.c 文件中。程序中已定义数组: a200, b200, 已定义变量 : cnt 请勿改动数据文件in.dat 中的任何数据、主函数main() 、读函数 readdat()和写函数writedat() 的内容。*/ #include #define max 200
19、int amax, bmax, cnt = 0 ; void jsval() /*/ int i,j,k,a,b,c,d; for(i=0; i 10*c+d) bcnt+=ai; for(i=0; i cnt-1; i+) k=i; for(j=i+1; j cnt; j+) if(bk bj) k=j; if(k!=i) a=bk; bk=bi; bi=a; /*/ 精品学习资料 可选择p d f - - - - - - - - - - - - - - 第 11 页,共 44 页 - - - - - - - - -学习必备欢迎下载 void readdat() int i ; file *
20、fp ; fp = fopen(in.dat, r) ; for(i = 0 ; i max ; i+) fscanf(fp, %d, &ai) ; fclose(fp) ; void main() int i ; readdat() ; jsval() ; printf( 满足条件的数=%dn, cnt) ; for(i = 0 ; i cnt ; i+) printf(%d , bi) ; printf(n) ; writedat() ; writedat() file *fp ; int i ; fp = fopen(out.dat, w) ; fprintf(fp, %dn,
21、cnt) ; for(i = 0 ; i =10 且 ab-cd=0 且 ab-cd=10 且两个数均是奇数, 同时两个新数的十位数字均不为零 ,则将满足此条件的四位数按从大到小的顺序存入数组b 中, 并要计算满足上述条件的四位数的个数cnt。out.dat 的内容应当为:5 8398 7996 5954 4313 2311 _ 老枪小于 200 个四位数之一 (共四题 ) code: /* 已知在文件in.dat 中存有若干个(个数 200)四位数字的正整数, 函数 readdat( )读取这若干个正整数并存入数组 xx 中。 请编制函数calvalue( ), 其功能要求 : 1. 求出这
22、文件中共有多少个正整数totnum; 2. 求出这些数中的各位数字之和是奇数的数的个数totcnt, 以及满足此条件的这些的算术平均值totpjz。最后main( )函数调用函数writedat() 把所求的结果输出到out.dat 文件中。注意 : 部分源程序存放在prog1.c 中。请勿改动数据文件in.da t 中的任何数据, 主函数 main()、 读数据函数readdat()和输出数据函数writedat()的内容。*/ #include #include #define maxnum 200 int xxmaxnum ; int totnum = 0 ; /* 文件 in.da t
23、 中共有多少个正整数*/ int totcnt = 0 ; /* 符合条件的正整数的个数*/ double totpjz = 0.0 ; /* 平均值*/ int readdat(void) ; void writedat(void) ; void calvalue(void) /*/ while(xxtotnum) if(xxtotnum/1000+xxtotnum/100%10+xxtotnum/10%10+xxtotnum)%2) totcnt+; totpjz+=xxtotnum; 精品学习资料 可选择p d f - - - - - - - - - - - - - - 第 16 页,共
24、 44 页 - - - - - - - - -学习必备欢迎下载totnum+; if(totcnt) totpjz/=totcnt; /*/ void main() int i ; clrscr() ; for(i = 0 ; i maxnum ; i+) xxi = 0 ; if(readdat() printf( 数据文件in.dat 不能打开 !007n) ; return ; calvalue() ; printf( 文件 in.dat 中共有正整数 =%d 个n, totnum) ; printf( 符合条件的正整数的个数=%d 个n, totcnt) ; printf( 平均值 =
25、%.2lfn, totpjz) ; writedat() ; int readdat(void) file *fp ; int i = 0 ; if(fp = fopen(in.dat, r) = null) return 1 ; while(!feof(fp) fscanf(fp, %d, &xxi+) ; fclose(fp) ; return 0 ; void writedat(void) file *fp ; fp = fopen(out.dat, w) ; fprintf(fp, %dn%dn%.2lfn, totnum, totcnt, totpjz) ; fclose(f
26、p) ; in.dat 文件内容如下:6045,6192,1885,3580,8544,6826,5493,8415,3132,5841, 6561,3173,9157,2895,2851,6082,5510,9610,5398,5273, 3438,1800,6364,6892,9591,3120,8813,2106,5505,1085, 5835,7295,6131,9405,6756,2413,6274,9262,5728,2650, 6266,5285,7703,1353,1510,2350,4325,4392,7573,8204, 7358,6365,3135,9903,3055,3
27、219,3955,7313,6206,1631, 5869,5893,4569,1251,2542,5740,2073,9805,1189,7550, 精品学习资料 可选择p d f - - - - - - - - - - - - - - 第 17 页,共 44 页 - - - - - - - - -学习必备欢迎下载4362,6214,5680,8753,8443,3636,4495,9643,3782,5556, 1018,9729,8588,2797,4321,4714,9658,8997,2080,5912, 9968,5558,9311,7047,6138,7618,5448,1466
28、,7075,2166, 4025,3572,9605,1291,6027,2358,1911,2747,7068,1716, 9661,5849,3210,2554,8604,8010,7947,3685,2945,4224, 7014,9058,6259,9503,1615,1060,7787,8983,3822,2471, 5146,7066,1029,1777,7788,2941,3538,2912,3096,7421, 9175,6099,2930,4685,8465,8633,2628,7155,4307,9535, 4274,2857,6829,6226,8268,9377,941
29、5,9059,4872,6072, out.dat 文件内容应当如下:160 69 5460.51 _ 老枪小于 200 个四位数之二 (共四题 ) code:/* 已知在文件in.dat 中存有若干个(个数 200)四位数字的正整数, 函数 readdat( )读取这若干个正整数并存入数组 xx 中。请编制函数calvalue( ), 其功能要求 : 1. 求出这文件中共有多少个正整数 totnum; 2. 求出这些数中的各位数字之和是偶数的数的个数totcnt, 以及满足此条件的这些数的算术平均值 totpjz。最后 main( )函数调用函数writedat() 把所求的结果输出到out
30、.dat 文件中。注意 : 部分源程序存放在prog1.c 中。请勿改动数据文件in.da t 中的任何数据, 主函数 main()、 读数据函数readdat()和输出数据函数writedat()的内容。*/ #include #include #define maxnum 200 int xxmaxnum ; int totnum = 0 ; /* 文件 in.da t 中共有多少个正整数*/ int totcnt = 0 ; /* 符合条件的正整数的个数*/ double totpjz = 0.0 ; /* 平均值*/ int readdat(void) ; void writedat(
31、void) ; void calvalue(void) /*/ for(; xxtotnum; totnum+) if(xxtotnum/1000+xxtotnum/100%10+xxtotnum/10%10+xxtotnum%10)%2=0) totcnt+; totpjz+=xxtotnum; if(totcnt) totpjz/=totcnt; /*/ void main() int i ; clrscr() ; 精品学习资料 可选择p d f - - - - - - - - - - - - - - 第 18 页,共 44 页 - - - - - - - - -学习必备欢迎下载for(i
32、 = 0 ; i maxnum ; i+) xxi = 0 ; if(readdat() printf( 数据文件in.dat 不能打开 !007n) ; return ; calvalue() ; printf( 文件 in.dat 中共有正整数 =%d 个n, totnum) ; printf( 符合条件的正整数的个数=%d 个n, totcnt) ; printf( 平均值 =%.2lfn, totpjz) ; writedat() ; int readdat(void) file *fp ; int i = 0 ; if(fp = fopen(in.dat, r) = null) re
33、turn 1 ; while(!feof(fp) fscanf(fp, %d, &xxi+) ; fclose(fp) ; return 0 ; void writedat(void) file *fp ;fp = fopen(out.dat, w) ; fprintf(fp, %dn%dn%.2lfn, totnum, totcnt, totpjz) ; fclose(fp) ; out.dat 文件内容应当如下:160 91 5517.1200 个四位数之三(共四题 ) code:/* 已知在文件in.dat 中存有若干个(个数 1)%2) totcnt+; totpjz+=xxt
34、otnum; if(totcnt) totpjz/=totcnt; /*/ void main() int i ; clrscr() ; for(i = 0 ; i maxnum ; i+) xxi = 0 ; if(readdat() printf( 数据文件in.dat 不能打开 !007n) ; return ; calvalue() ; printf( 文件 in.dat 中共有正整数 =%d 个n, totnum) ; printf( 符合条件的正整数的个数=%d 个n, totcnt) ;printf( 平均值 =%.2lfn, totpjz) ; writedat() ; int
35、 readdat(void) file *fp ; int i = 0 ; if(fp = fopen(in.dat, r) = null) return 1 ; while(!feof(fp) fscanf(fp, %d, &xxi+) ; fclose(fp) ; return 0 ; void writedat(void) file *fp ; fp = fopen(out.dat, w) ; fprintf(fp, %dn%dn%.2lfn, totnum, totcnt, totpjz) ; fclose(fp) out.dat 文件内容应当如下:160 80 5537.54
36、 _ 老枪小于 200 个四位数之四 (共四题 ) code: /* 精品学习资料 可选择p d f - - - - - - - - - - - - - - 第 20 页,共 44 页 - - - - - - - - -学习必备欢迎下载已知在文件in.dat 中存有若干个(个数 0; totnum+) if(xxtotnum1)%2=0) totcnt+; totpjz+=xxtotnum; if(totcnt) totpjz/=totcnt; /*/ void main() int i ; clrscr() ; for(i = 0 ; i maxnum ; i+) xxi = 0 ; if(
37、readdat() printf( 数据文件in.dat 不能打开 !007n) ; return ; calvalue() ; printf( 文件 in.dat 中共有正整数 =%d 个n, totnum) ; printf( 符合条件的正整数的个数=%d 个n, totcnt) ; printf( 平均值 =%.2lfn, totpjz) ; writedat() ; int readdat(void) file *fp ; 精品学习资料 可选择p d f - - - - - - - - - - - - - - 第 21 页,共 44 页 - - - - - - - - -学习必备欢迎下
38、载int i = 0 ; if(fp = fopen(in.dat, r) = null) return 1 ; while(!feof(fp) fscanf(fp, %d, &xxi+) ; fclose(fp) ; return 0 ; void writedat(void) file *fp ; fp = fopen(out.dat, w) ; fprintf(fp, %dn%dn%.2lfn, totnum, totcnt, totpjz) ; fclose(fp) ; out.dat 文件内容应当如下:160 80 5447.93 _ 老枪英文文章字符串处理(共10 题)之一
39、code: /* 函数 readdat( )实现从文件in.dat 中读取一篇英文文章存入到字符串数组xx 中; 请编制函数sortchard( ), 其函数的功能是: 以行为单位对字符按从大到小的顺序进行排序, 排序后的结果仍按行重新存入字符串数组xx 中。最后main()函数调用函数writedat() 把结果 xx 输出到文件out2.da t 中。例: 原文 : dae,bfc. ccbbaa 结果 : fedcba., bbccaa 原始数据文件存放的格式是: 每行的宽度均小于80 个字符 , 含标点符号和空格。注意 : 部分源程序存放在prog1.c 中。请勿改动主函数main(
40、)、读数据函数readdat()和输出数据函数 writedat() 的内容。*/ #include #include #include char xx5080 ; int maxline = 0 ; /* 文章的总行数*/ int readdat(void) ; 精品学习资料 可选择p d f - - - - - - - - - - - - - - 第 22 页,共 44 页 - - - - - - - - -学习必备欢迎下载void writedat(void) ; void sortchard(void) /*/ int i,j,k,m,n; char ch; for(i=0; i ma
41、xline; i+) j=strlen(xxi); for(m=0; m j-1; m+) k=m; for(n=m+1; n j; n+) if(xxik xxin) k=n; if(k!=m) ch=xxik; xxik=xxim; xxim=ch; /*/ void main() clrscr() ; if(readdat() printf( 数据文件in.dat 不能打开 !n007) ; return ; sortchard() ; writedat() ; int readdat(void) file *fp ; int i = 0 ; char *p ; if(fp = fope
42、n(in.dat, r) = null) return 1 ; while(fgets(xxi, 80, fp) != null) p = strchr(xxi, n) ; if(p) *p = 0 ; i+ ; maxline = i ; fclose(fp) ; return 0 ; void writedat(void) file *fp ; int i ; clrscr() ; 精品学习资料 可选择p d f - - - - - - - - - - - - - - 第 23 页,共 44 页 - - - - - - - - -学习必备欢迎下载fp = fopen(out2.dat, w
43、) ; for(i = 0 ; i maxline ; i+) printf(%sn, xxi) ; fprintf(fp, %sn, xxi) ; fclose(fp) ; in.dat 文件内容为:you can create an index on any field, on several fields to be used together, or on parts thereof, that you want to use as a key. the keys in indexes allow you quick access to specific records and def
44、ine orders for sequential processing of a isam file. after you no longer need an index, you can delete it. addition and indexes have no effect on the data records or on other indexes. you may want a field in field in each record to uniquely identify that record from all other records in the file. fo
45、r example, the employee number field is unique if you do not assign the same number to two different employees, and you never reassign these numbers to other employees. if you wish to find or modify the record belonging to a specific employee, this unique field saves the thouble of determining wheth
46、er you have the correct record. if you do not have a unique field, you must find the first record the matches your key and determine whether the record is the one you want. if it is not the correct one, you must search again to find others. if you know that you have a unique field within your record
47、s, you can include this fact in the key description, and isam will allow only unique keys. for example, if you specify that the employee numbers are unique, isam only lets you add records to the file for, or 精品学习资料 可选择p d f - - - - - - - - - - - - - - 第 24 页,共 44 页 - - - - - - - - -学习必备欢迎下载change nu
48、mbers to, employee numbers that do not alreadly exist int file. out2.dat 文件内容应当为:yxvuuttsssrroooonnnnnnllliiiffeeeeeeeeeddddccbaaaaay, yywuuttttttttsssrrrrpoooooonnkhhhhgfeeeeeeeaaaaat., yyxwuutssssssrrqpoooonnnnllkkiiiiiiffeeeeeeeeddddccccccaaa yuuttssssrrrrrrqpooooooonnnnllliiiggffffeeeeeeedcaasmi
49、aa. yxxvuttttsooonnnnnnnnliiiiihffeeeeeeeeeeedddddddccaaaaa., xtttssrrrrooooonnnihheeeeedddcaa. yyywuuutttttrrqooonnnnnmllliiiiiiihhfffeeeeeeddddccaaaaay yxtttsrrrrrrrppoooooonmmmllllliihhhffeeeeeeeeeeddccaafe., ywuuuuuttttssssrrqooooonnnnmmmliiiiihgffeeeeeeddbbaan yyvuuttttsssssrrrrrpoooonnnnnmmlii
50、hhgffeeeeeeeeeeeeddbaa, yyywutttssrrrpoooooooonnnmmlliiiihhggfffeeeeeedddcbai. yvuuuttttssssrqppooonnnmmllliiiiiiihhhgfffeeeeeeeeeeeddccba, ywvutttrrrrrooohhhheeeeeedccca. yyvuuuuuttttssrrrqooooonnnmliiiihhffffeeeeeddddcaai, yyywuuttttttssrrrrroooonnnmmkiihhhhhheeeeeeeeeeeedddccaa ywuuttttttttssssrr
51、rroooooonnnnnmiiiihhhgffeeeeedcccaaaai., yyyywwvuuuuuutttsrrrqoooooonnnlkiiiihhhffeeeeddcaaai, yywwuttttssrpooonnnnnnllllllkiiiiiihhfeeeedddccccaaaasmia, yyyyxuuuutttsssrrrqpppooonnmmmllkiiihhffeeeeeeeeeeecbaaaf., yyuuutttssrrrrqoooooonnnllliihhgffeeeeeedddccaasmia, yyxuuttttttsssrrrpoooonnnnmmmllll
52、iiihfeeeeeeeeddbbaaa., _ 字符串处理之二code: /* 函数 readdat( )实现从文件in.dat 中读取一篇英文文章存入到字符串数组xx 中; 请编制函数convertchara(), 其函数的功能是: 以行为单位把字符串中的所有小写字母改写成该字母的下一个字母 , 如果是字母z, 则改写成字母a,大写字母和其它字符保持不变。把已处理的字符串仍按行重新存入字符串数组xx 中。最后 main()函数调用函数writedat() 把结果 xx 输出到文件out3.dat 中。例: 原文 : adb.bcdza abck.llhj 结果 : aec.bdeab bc
53、dl.llik 原始数据文件存放的格式是: 每行的宽度均小于80 个字符 , 含标点符号和空格。注意 : 部分源程序存放在prog1.c 中。请勿改动主函数main( )、读数据函数readdat()和输出数据函数 writedat() 的内容。*/ 精品学习资料 可选择p d f - - - - - - - - - - - - - - 第 25 页,共 44 页 - - - - - - - - -学习必备欢迎下载#include #include #include char xx5080 ; int maxline = 0 ; /* 文章的总行数*/ int readdat(void) ;
54、void writedat(void) ; void convertchara(void) /*/ int i,j; for(i=0; i maxline; i+) for(j=0; j =a)&(xxijz) xxij+; /*/ void main() clrscr() ; if(readdat() printf( 数据文件in.dat 不能打开 !n007) ; return ; convertchara() ; writedat() ; int readdat(void) file *fp ; int i = 0 ; char *p ; if(fp = fopen(in.dat
55、, r) = null) return 1 ; while(fgets(xxi, 80, fp) != null) p = strchr(xxi, n) ; if(p) *p = 0 ; i+ ; maxline = i ; fclose(fp) ; return 0 ; void writedat(void) file *fp ; int i ; clrscr() ; 精品学习资料 可选择p d f - - - - - - - - - - - - - - 第 26 页,共 44 页 - - - - - - - - -学习必备欢迎下载fp = fopen(out3.dat, w) ; for(
56、i = 0 ; i maxline ; i+) printf(%sn, xxi) ; fprintf(fp, %sn, xxi) ; fclose(fp) ; out3.dat 文件内容应当如下:ypv dbo dsfbuf bo joefy po boz gjfme, po tfwfsbm gjfmet up cf vtfe uphfuifs, ps po qbsut uifsfpg, uibu zpv xbou up vtf bt b lfz. tif lfzt jo joefyft bmmpx zpv rvjdl bddftt up tqfdjgjd sfdpset boe efgjof
57、 psefst gps tfrvfoujbm qspdfttjoh pg b isam gjmf. agufs zpv op mpohfs offe bo joefy, zpv dbo efmfuf ju. aeejujpo boe joefyft ibwf op fggfdu po uif ebub sfdpset ps po puifs joefyft. ypv nbz xbou b gjfme jo gjfme jo fbdi sfdpse up vojrvfmz jefoujgz uibu sfdpse gspn bmm puifs sfdpset jo uif gjmf. fps f
58、ybnqmf, uif enqmpzff nvncfs gjfme jt vojrvf jg zpv ep opu bttjho uif tbnf ovncfs up uxp ejggfsfou fnqmpzfft, boe zpv ofwfs sfbttjho uiftf ovncfst up puifs fnqmpzfft. ig zpv xjti up gjoe ps npejgz uif sfdpse cfmpohjoh up b tqfdjgjd fnqmpzff, uijt vojrvf gjfme tbwft uif uipvcmf pg efufsnjojoh xifuifs
59、zpv ibwf uif dpssfdu sfdpse. ig zpv ep opu ibwf b vojrvf gjfme, zpv nvtu gjoe uif gjstu sfdpse uif nbudift zpvs lfz boe efufsnjof xifuifs uif sfdpse jt uif pof zpv xbou. ig ju jt opu uif dpssfdu pof, zpv nvtu tfbsdi bhbjo up gjoe puifst. ig zpv lopx uibu zpv ibwf b vojrvf gjfme xjuijo zpvs sfdpset,
60、zpv dbo jodmvef uijt gbdu jo uif lfz eftdsjqujpo, boe isam xjmm bmmpx pomz vojrvf lfzt. fps fybnqmf, jg zpv tqfdjgz uibu uif fnqmpzff ovncfst bsf vojrvf, isam pomz mfut zpv bee sfdpset up uif gjmf gps, ps 精品学习资料 可选择p d f - - - - - - - - - - - - - - 第 27 页,共 44 页 - - - - - - - - -学习必备欢迎下载dibohf ovncfst up, fnqmpzff ovncfst uibu ep opu bmsfbemz fyjtu jou
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 44 选择性必修1 第七单元 第36讲 免疫失调和免疫学的应用
- 29 必修2 第五单元 第25讲 DNA的结构、复制和基因的本质
- 教学课件征集意见
- 高端写字楼车位租赁合同补充协议范本
- 互联网营销推广服务购销合同
- 高端酒店厨房承包与维护保养合作协议
- 建筑材料叉车工安全防护协议
- 矿业开采权质押融资协议模板
- 车辆股权转让与品牌授权及全球销售网络合作协议
- 电力安全知识相关工作场景常见问题测试试卷
- 电厂安规考试题库及答案
- 2021-2022学年浙江省杭州市拱墅区英语小升初新生分班考试卷 附解析
- 2024-2025学年人教版(2024)初中英语七年级下册教学工作总结(共4套)
- Unit 1 Happy Holiday 第5课时(Section B 2a-3c) 2025-2026学年人教版英语八年级下册
- 2025年中国三元乙丙橡胶市场调查研究报告
- 常见耐药菌感染诊疗与防控
- 征兵体检外科标准
- 小学生预防拐骗教育课件
- 床上用品采购 投标方案
- 2025-2030年中国基于细胞的人源化小鼠模型行业市场现状供需分析及投资评估规划分析研究报告
- 2025至2030中国无线通讯检测行业市场发展分析及竞争格局与投资机会报告
评论
0/150
提交评论