替换字符问题(vc6.0)-------很奇怪在tc下可以
替代关系:f(p)=p*11 mod 256 (p是数组中某一个字符的ASCII值,f(p)是计算后新字符的ASCII值),如果原字符的ASCII值是偶数或计算后f(p)值小于等于32,则该字符不变,否则将f(p)所对应的字符进行替代。#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <ctype.h>
unsigned char xx[50][80] ;
int maxline = 0 ;/* 文章的总行数 */
int ReadDat(void) ;
void WriteDat(void) ;
void encryptChar()
{
int i,j ;
for(i=0;i<maxline;i++)
for(j=0;j<strlen(xx[i]);j++)
if(xx[i][j]*11%256<=32||xx[i][j]*11%256>130) continue ;
else xx[i][j]=xx[i][j]*11%256 ;
}
main()
{
clrscr() ;
if(ReadDat())
{
printf("数据文件ENG4.IN不能打开!\n\007") ;
return ;
}
encryptChar() ;
WriteDat() ;
}
int ReadDat(void)
{
FILE *fp;
int i = 0 ;
unsigned char *p ;
if((fp = fopen("ENG4.IN", "r")) ==NULL) return 1 ;
while(fgets(xx[i], 80, fp) !=NULL)
{
p = strchr(xx[i], '\n ') ;
if(p) *p = 0;
i++ ;
}
maxline = i ;
fclose(fp) ;
return 0 ;
}
void WriteDat(void)
{
FILE *fp ;
int i ;
fp = fopen("PS4.DAT", "w") ;
for(i = 0 ; i < maxline ; i++)
{
printf("%s\n", xx[i]) ;
fprintf(fp, "%s\n", xx[i]) ;
}
fclose(fp) ;
}
VC下,Ctrl+f7正常,按F7就提示错误