65,186
社区成员




int ReadDat()
{
FILE *fp;
int i = 0;
char *p;
if(NULL == (fp = fopen("G:\\eng.in","r")))
{
return 1;
}
while(fgets(xx[i],80,fp) != NULL)
{
i++;
}
maxline = i;
fclose(fp);
}
#include <stdio.h>
#include <string.h>
#include <ctype.h>
char xx[50][80];
int maxline = 0;
int ReadDat();
void WriteDat();
void DelWord();
void main()
{
if(ReadDat())
{
printf("数据文件ENG.IN不能打开\n\007");
return;
}
DelWord();
WriteDat();
getchar();
}
int ReadDat()
{
FILE *fp;
int i = 0;
char *p;
if(NULL == (fp = fopen("G:\\eng.in","r")))
{
return 1;
}
while(fgets(xx[i],80,fp) != NULL)
{
i++;
}
maxline = i;
fclose(fp);
}
void WriteDat()
{
FILE *fp;
int i;
fp = fopen("G:\\PSOUT.OUT","w");
for(i=0;i<maxline;i++)
{
printf("%s\n",xx[i]);
fprintf(fp,"%s\n",xx[i]);
}
fclose(fp);
}
void DelWord()
{
int i ; //行数
int j ; //单词的个数
int k ; //单词的序数
char word[21]; //用来存放一个单词的字符数组
char str[80]; //用来存放颠倒的字符串
char *p; //用来指向行的指针
for(i=0;i<maxline;i++)
{
memset(word,0,21); //清空word
memset(str,0,80); //清空str
j = 0; //单词的个数清为0
k = 0; //单词的序数清0
p = xx[i]; //把一行的指针赋给p
while(*p) //如果字符不为0
{
if(isalpha(*p)) //如果*p是字母
{
word[j++] = *p++; //把一个字母放入word中
if(*p) //如果*p不是0则进入下一次循环,判断*p是否为字母
{
continue;
}
}
//*p不是字母的情况
if(strlen(word)) //word长度不为0说明word里有一个单词
{
k++; //单词的个数加1
}
if(k%2==0) //单词的序数为奇数(数组的下标从0开始,所能判断偶数)
{
strcat(str,strrev(word)); //把单词倒转存入str中
}
//清0 未下次循环做准备
j = 0;
memset(word,0,21);
while(*p && (!isalpha(*p))) // *p不为0且不是字母
p++;
}
strcpy(xx[i],str);
}
}
看看你有没包含 file.open所需要的头文件
c++里面,我直接
#include <fstream>
ofstream of("...");