青浦墓园:C语言上机题.~~~~~~~~~这道题不用指针怎样做?

来源:百度文库 编辑:杭州交通信息网 时间:2024/03/29 17:06:51
函数ReadDat()实现从文件in.dat中读取一篇英文文章到字符串数组xx中;请编制函数delword()分别按行删除在行中的空格,标点符号以及单词的序数为奇数的单词,余下的单词倒置后仍按行顺序重新存入数组xx中,最后调用函数writedat()把结果输出到文件out.dat中。
例如:原文:If you do not have a unique field.
结果:uoytonadleif
原始数据文件格式:每行宽度均小于80个字符,含标点符号和空格。
注意:文章中每单词均小于20个字符。

#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 DelWord(void)
{

}

void main()
{
if(ReadDat()) {
printf("数据文件IN.DAT不能打开!\n\007") ;
return ;
}
DelWord() ;
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) xx[i][p - xx[i]] = 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[i]) ;
fprintf(fp, "%s\n", xx[i]) ;
}
fclose(fp) ;
}
第一位回答的,不正确啊~`
第二个回答的也不正确,什么乱七八糟的,你们懂不懂C语言啊~~~~~~~~~~~~