|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 旭日东升 于 2011-4-23 17:02 编辑
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define LINE 70
#define COL 80
char inBuf[LINE][COL];
int totleLine = 0; //文章的总行数
int readData(void);
void writeData(void);
void replaceChar()
{
}
void main()
{
system("CLS");
if(readData())
{
printf("IN.DAT can't be open!\n\007");
return;
}
replaceChar();
writeData();
}
int readData(void)
{
FILE *fp;
int i = 0;
char *p;
if((fp = fopen("IN.DAT", "r")) ==NULL) return 1;
while(fgets(inBuf[i], COL, fp) !=NULL)
{
p = strchr(inBuf[i], '\n');
if(p) *p = 0;
i++;
}
totleLine = i;
fclose(fp);
return 0;
}
void writeData(void)
{
FILE *fp;
int i;
fp = fopen("OUT.DAT", "w");
for(i = 0; i < totleLine; i++)
{
printf("%s\n", inBuf[i]);
fprintf(fp, "%s\n", inBuf[i]);
}
fclose(fp);
}
这是题目
下面是要编写的函数的代码:
int i, j;
for(i=0; i<LINE; i++)
{
for(j=0; j<COL; j++)
{
if(inBuf[i][j]>='a' && inBuf[i][j]<='z')
{
if(inBuf[i][j] == 'a')
{
inBuf[i][j] = 'z';
}
else
{
inBuf[i][j] = char(int(inBuf[i][j])-1);
}
}
}
} |
|