[说明]
从文件IN.DAT中读取一篇英文文章存入到字符串数组XX中; 请编写程序,其功能是:以行为单位把字符串中的所有小写字母o左边的字符串内容移到该串的右边存放,然后把小写字母o删除,余下的字符串内容移到已处理字符串的左边存放,最后把已处理的字符串仍按行重新存入字符串数组XX中,最后调用函数writedat( )把结果XX输出到文件OUT5.DAT中。
原始数据文件存放的格式是:每行的宽度均小于80个字符,含标点符号和空格。
[函数]
# include "stdio.h"
# include "string.h"
# include "conio.h"
# include "ctype.h"
# include "mem.h"
unsigned char xx[50][80] ;
int maxline=0;
int readdat (void) ;
void writedat (void) ;
/*将题目要求的字符串中所有小写字母。左边的字符串内容移到该串的右边存放,即将串中*/
/*“最后”一个字母o左右两侧的内容互换*/
void StrOR (void)
int i;
char *p1, *p2 , t[80];
for (i=0;i<maxline; i++)
p2=xx [i] ;
while (*p2) /*找到最后一个,’o’ */
if ( (1) ) p1=p2
p2++;
strcat (t,p1+1) ;
strcat (t,xx [i]) ;
p1=xx[i];
p2=t ;
while(*p2) /*删符’o’*/
jf( (2) )( (3) )=*p2;
p2++;
(4) ;
void main ( )
clrscr ( ) ;
if (readdat ( )
printf("Can’t open the file IN.DAT!/n");
return;
StrOR ( ) ;
writedat ( ) ;
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)
i++;
maxline= (5) ;
fclose (fp) ;
return 0;
void writedat (void)
FILE *fp;
int i;
fp=fopen ("in.dat " , "w") ;
for (i=0; i<maxline; i++)
printf("%s/n",xx[i]);
fprintf(fp, "%s/n",xx[i]) ;
fclose (fp) ;
题库:初级程序员
类型:填空题
时间:2017-07-03 12:01:10
免费下载:《填空集》Word试卷
[说明]
从文件IN.DAT中读取一篇英文文章存入到字符串数组XX中; 请编写程序,其功能是:以行为单位把字符串中的所有小写字母o左边的字符串内容移到该串的右边存放,然后把小写字母o删除,余下的字符串内容移到已处理字符串的左边存放,最后把已处理的字符串仍按行重新存入字符串数组XX中,最后调用函数writedat( )把结果XX输出到文件OUT5.DAT中。
原始数据文件存放的格式是:每行的宽度均小于80个字符,含标点符号和空格。
[函数]
# include "stdio.h"
# include "string.h"
# include "conio.h"
# include "ctype.h"
# include "mem.h"
unsigned char xx[50][80] ;
int maxline=0;
int readdat (void) ;
void writedat (void) ;
/*将题目要求的字符串中所有小写字母。左边的字符串内容移到该串的右边存放,即将串中*/
/*“最后”一个字母o左右两侧的内容互换*/
void StrOR (void)
int i;
char *p1, *p2 , t[80];
for (i=0;i<maxline; i++)
p2=xx [i] ;
while (*p2) /*找到最后一个,’o’ */
if ( (1) ) p1=p2
p2++;
strcat (t,p1+1) ;
strcat (t,xx [i]) ;
p1=xx[i];
p2=t ;
while(*p2) /*删符’o’*/
jf( (2) )( (3) )=*p2;
p2++;
(4) ;
void main ( )
clrscr ( ) ;
if (readdat ( )
printf("Can’t open the file IN.DAT!/n");
return;
StrOR ( ) ;
writedat ( ) ;
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)
i++;
maxline= (5) ;
fclose (fp) ;
return 0;
void writedat (void)
FILE *fp;
int i;
fp=fopen ("in.dat " , "w") ;
for (i=0; i<maxline; i++)
printf("%s/n",xx[i]);
fprintf(fp, "%s/n",xx[i]) ;
fclose (fp) ;
本题关键词:数字字符串,符号数字试验,程序性文件,中文警示说明,串通投标行为,文件澄清说明,字文恺,规章文件,申请文件,文化功能;