if(b[i]
b[j]=qw;}
}
void readDat()
{
int i ;
FILE *fp ;
fp = fopen("in.dat", "r") ;
for(i = 0 ; i < MAX ; i++) fscanf(fp, "%d", &a[i]) ;
fclose(fp) ;
}
void main()
{
int i ;
readDat() ;
jsVal() ;
printf("满足条件的数=%d\n", cnt) ;
for(i = 0 ; i < cnt ; i++) printf("%d ", b[i]) ;
printf("\n") ;
writeDat() ;
}
writeDat()
{
FILE *fp ;
int i ;
fp = fopen("out.dat", "w") ;
fprintf(fp, "%d\n", cnt) ;
for(i = 0 ; i < cnt ; i++) fprintf(fp, "%d\n", b[i]) ;
fclose(fp) ;
}
★☆题目3(无忧id 133题;捷成id 59、99字符串
位置倒置题)
函数ReadDat( )实现从文件IN.DAT中读取一篇英文
文章存入到字符串数组xx中;请编制函数
StrOR( ),其函数的功能是:以行为单位依次把
字符串中所有小写字母o左边的字符串内容
移到该串的右边存放,然后把小写字母o删
除,余下的字符串内容移到已处理字符串的
左边存放,之后把已处理的字符串仍按行重
新存入字符串数组xx中。最后main()函数调用
函数WriteDat()把结果xx输出到文件OUT5.DAT中。
例如:原文:n any field.Yu can create an
index
you have the correct
record.
结果:n any field. Yu can create
an index
rd. yu have the crrect rec
原始数据文件存放的格式是:每行的宽度均小于
80个字符,含标点符号和空格。
注意:部分源程序存放在文件prog1.c中。
请勿改动主函数main()、读数据函数ReadDat()
和输出数据函数WriteDat()的内容。
#include
#include
#include
char xx[50][80] ;
int maxline = 0 ; /* 文章的总行数*/
int ReadDat(void) ;
void WriteDat(void) ;
void StrOR(void)
{int i,righto,j,s,k;
char tem[80];
for(i=0;ifor(j=strlen(xx[i])-1;j>=0;j--)
{ k=0;
memset(tem,0,80); /*初始化字符串数
组tem*/
if(xx[i][j]=='o') /*如果当前字符为'o',
进入以下语句*/
{righto=j; /*则将此字符中位置j的
值赋给righto*/
for(s=righto+1;stem[k++]=xx[i][s]; /*从righto
的下一跳开始将其后所有的字符都存入到tem中*/
for(s=0;s行首部开始到出现字符'o'的位置(righoto)之前开始
循环*/
if(xx[i][s]!='o')
tem[k++]=xx[i][s]; /*将不是字符'o'的字符全存入
到tem中*/
strcpy(xx[i],tem); /*将当前已处
理的字符重新存入当前行xx*/
}
else continue;
}
}
void main()
{
clrscr() ;
if(ReadDat()) {
printf("数据文件IN.DAT不能打开!\n\007") ;
return ;
}
StrOR() ;
WriteDat() ;
}