|
阅读:438回复:1
[求助]一道三级C语言上机题。
函数ReadDat( )实现从文件IN.DAT中读取一篇英文文章存入到字符串数组xx中; 请编制函数StrOL( ), 其函数的功能是: 以行为单位对行中以空格或标点符号为分隔的所有单词进行倒排,同时去
除标点符号,之后把已处理的字符串(应不含标点符号)仍按行重新存入字符串数组xx中。最后main()函数调用函数WriteDat()把结果xx输出到文件OUT6.DAT中。 例如: 原文: You He Me I am a student. 结果: Me He You student a am I 原始数据文件存放的格式是: 每行的宽度均小于80个字符, 含标点符号和空格。 PROG1.C # include"stdio.h" # include"string.h" # include"conio.h" # include"ctype.h" char xx[50][80]; int maxline=0; int ReadDat(void); void WriteDat(void); void StrOR(void) { } void main() {clrscr(); if(ReadDat()) {printf("Can't open the file!\n"); return;} StrOR(); WriteDat(); system("pause"); } int ReadDat(void) {FILE *fp;int i=0;char *p; if((fp=fopen("in.dat","r"))==NULL) return 1; while(fgets(xx,80,fp)!=NULL) {p=strchr(xx,'\n'); if(p) *p=0; i++; } maxline=i; fclose(fp); return 0; } void WriteDat(void) {FILE *fp; int i; fp=fopen("out.dat","w"); for(i=0;i<maxline;i++) {printf("%s\n",xx); fprintf(fp,"%s\n",xx); } fclose(fp); } IN.DAT You He Me I am a student 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 define 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. For 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 whether 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 records, 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 change numbers to, employee numbers that do not alreadly exist int file. OUT.DAT Me He You student a am I used be to fields several on field any on index an create can You The key a as use to want you that thereof parts on or together define and records specific to access quick you allow indexes in keys longer no you After file ISAM a of processing sequential for orders effect no have indexes and Addition it delete can you index an need indexes other on or records data the on that identify uniquely to record each in field in field a want may You Employee the example For file the in records other all from record two to number same the assign not do you if unique is field Number other to numbers these reassign never you and employees different a to belonging record the modify or find to wish you If employees determining of thouble the saves field unique this employee specific record correct the have you whether record first the find must you field unique a have not do you If you one the is record the whether determine and key your matches the others find to again search must you one correct the not is it If want you records your within field unique a have you that know you If only allow will ISAM and description key the in fact this include can are numbers employee the that specify you if example For keys unique change or for file the to records add you lets only ISAM unique file int exist alreadly not do that numbers employee to numbers 答案程序是: void StrOL(void) { int i,j,k,m,n,ll; char yy[80]; for(i=0; i < maxline; i++) { ll=strlen(xx); k=n=0; for(j=ll-1; j>=0; j--) { if(isalpha(xx[j])) k++; else { for(m=1; m<=k; m++) yy[n++]=xx[j+m]; k=0; } if(xx[j]==' ') yy[n++]=' '; } for(m=1; m<=k; m++) yy[n++]=xx[j+m]; yy[n]=0; strcpy(xx,yy); } } 不知道算法的思想。哪位好人指点迷津。 多谢。 |
|
|
1C#
发布于:2004-09-20 22:40
Re:[求助]一道三级C语言上机题。
答案都有了,还用那么费劲在这问吗,有时间上机调试一下也比这强啊.程序是练的不是看的. |
|