| Gzu521.com我的学习网 |
|
(本题用于笔试,需对文件调用代码作部分修改方可执行) 函数readdat()实现从文件in.dat中读取一篇英语文章存入到字符串数组xx中;请编制函数stror(),其函数功能是:以行为单位把字符串中的所有小写字母o左边的字符串内容移到该串的右边存入,然后把小写字母o删除,余下的字符串内容移到已处理字符串的左边存放。最后把已处理的字符串仍按行重新存入字符串数组xx中,最后调用函数writedat()把结果xx输出到文件out.dat中。原始数据文件存放的格式是:每行宽度均小于80个字符,含标点符号和空格。 原文 you can create an index on any field you have the correct record. 结果 n any field.you can create an index rd.yu have the crrect rec 程序: #include #include #include char xx[50][80]; int maxline=0; /*文章总行数*/ int readdat(void); void writedat(void); void stror(void) { int i,j,k,index,strl; char ch; for (i=0;i strl=strlen(xx[i]); index=strl; for (j=0;j { for (k=j;k index=j; } for (j=strl-1;j>=index;j--) { ch=xx[i][strl-1]; for (k=strl-1;k>0;k--) xx[i][k]=xx[i][k-1]; xx[i][0]=ch; } } } void main() { clrscr(); if (readdat()) { printf("数据文件in.dat不能打!\n\007"); 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[i],80,fp)!=null) { p=strchr(xx[i],’\n’); if (p) *p=0; i++; } maxline=i; fclose(p); return 0; } void writedat(void) { file *fp; int i; fp=fopen("out.dat","w"); for (i=0;i<=maxline;i++) { printf("%s\n",xx[i]); fprintf(fp,"%s\n",xx[i]); } fclose(fp); } |
责任编辑:gzu521