函数指针、函数意外结束问题
#include<stdio.h>
#include<math.h>
#include<time.h>
#include<stdlib.h>
#include<assert.h>
/*********************************************/
void main()
{
clock_t start,end,over;
int convert(int m);
void process( int size,unsigned char *source,unsigned char *destination,int (*mm)( int));
FILE *file;
int width,height,size;
char *name=NULL;
int a=1;
while(a)
{
printf("Please input your file name: \n");
scanf("%s",name);
if((file=fopen(name,"rb"))=NULL)
printf("Input error!\nEnter 0 to exit.\n");
scanf("%d",&a);
}
a=1;
while(a)
{
printf("Please input the width of your file:\n");
scanf("%d",&width);
if(width<=0)
printf("Input error!\nEnter 0 to exit.\n");
scanf("%d",&a);
}
a=1;
while(a)
{
printf("Please input the height of your file:\n");
scanf("%d",&height);
if(width<=0)
printf("Input error!\nEnter 0 to exit.\n");
scanf("%d",&a);
}
size=(int)(width*height);
unsigned char *source,*destination;
source=(unsigned char *)calloc(size,sizeof(char));
destination=(unsigned char *)calloc(size,sizeof(char));
fread(source,size,1,file);
fclose(file);
start=clock();
end=clock();
over=end-start;
start=clock();
process(size,source,destination, convert);
end=clock();
printf("time: %4.2f s\n",(float)(end-start-over)/CLK_TCK);
fwrite(destination,size,1,file);
fclose(file);
free(source);
free(destination);
}
/*********************************************/
/********************************************/
void process( int size,unsigned char *source,unsigned char *destination, int (*mm)( int ))
{
int i=0,temp;
for(i;i<size;i++)
{
temp=(*mm)(*source(i));//报错:term does not evaluate to a function
if(temp<0)
temp=0;
if(temp>255)
temp=255;
*destination(i)=temp;//报错:term does not evaluate to a function
}
/**************************************************/
/**************************************************/
int convert(int m)
{
int Gray_Level,a=1,back;//报错:local function definitions are illegal
while(a)
{
printf("Please input the Gray_Level of your image:\n");
scanf("%d",&Gray_Level);
if(Gray_Level<=0)
printf("Input error!\nEnter 0 to exit.\n");
scanf("%d",&a);
}
back=Gray_Level-1-m);
return back;
}//报错:unexpected end of file found
编译时提示有四个错误,我在程序中标明了,我不知道错在哪里,该怎么改,谢谢。