关于fopen一系列的函数和指针搞不懂
我读一个txt文件,然后按照定义的change算法来文件进行修改再在屏幕上输出,但是输出总是乱七八糟的东西,然后提示停止工作change只有for循环是对的,其余的我不清楚哪里不对
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main()
{
long int n;
void change (FILE* m,long int num);
FILE *read;
read=fopen("data_v.txt","r");
fseek(read,0,SEEK_SET);
fseek(read,0,SEEK_END);
n=ftell(read);
if (read==NULL)
{
printf("can't open this file\n ");
exit(0);
}
change(read,n);
fclose(read);
return 0;
}
void change (FILE* m,long int num)
//a=97 A=65 z=122 Z=90
{
char x[5]={'h','e','l','l','o'};
char *f=(char *)malloc(num);
int i,j,l;
fread(f,1,num,m);
for (i=0;i<5;i++)
{
x[i]=x[i]-97;
}
for (i=0;i<num;i++)
{
if(f[i]<97)
f[i]=f[i]-65;
else
f[i]=f[i]-97;
}
for (i=0;i<num;i++)
{
if (f[i]>=0)
f[i]=(f[i]+x[i%5])%26+65;
else
f[i]=f[i]+65;
printf("%c",m[i]);
}
}