Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main(int argc,char *argv[])
- {
- FILE *fpio;
- FILE *fpio2;
- int i,height,width;
- float *file;
- //float *file3;
- //float start,end;
- float total,average;
- float r_average;
- if(argc!=5)
- {
- fprintf(stderr,"Usage: %s\n(2)Input_R_READ_filename\n(3)width\n(4)height\n(5)output_filename",argv[0]);
- exit(1);
- }
- printf("Input FILE NAME:%s\n",argv[1]);
- printf("output file name:%s\n",argv[2]);
- width = atoi(argv[2]); printf("W = %d,", width);
- height = atoi(argv[3]); printf("H = %d\n", height);
- /*---------ÉÅÉÇÉäÇÃé©ìÆäÑìñ----------*/
- file= (float *)malloc(width*height*sizeof(float));
- /*----------------ì¸óÕRâÊëúÉtÉ@ÉCÉãÇÃÉIÅ[ÉvÉìäJén----------------------*/
- if((fpio=fopen(argv[1],"rb"))==NULL)
- { /*ÉtÉ@ÉCÉãÇÃÉIÅ[ÉvÉì*/
- fprintf(stderr,"input file open error\n");
- exit(1);
- }
- fread((float *)file,sizeof(float),width*height,fpio);
- /*----------------âÊëúÉtÉ@ÉCÉãÇÃÉIÅ[ÉvÉìèIóπ----------------------*/
- /*----------------ì¸óÕNIRâÊëúÉtÉ@ÉCÉãÇÃÉIÅ[ÉvÉìäJén----------------------*/
- //fread((float *)file3,sizeof(float),width*height,fpo);
- if((fpio2=fopen(argv[4],"w"))==NULL)
- { /*ÉtÉ@ÉCÉãÇÃÉIÅ[ÉvÉì*/
- fprintf(stderr,"input file open error\n");
- exit(1);
- }
- total=0;
- for(i=0;i<height*width;i++)
- {
- if(file[i]<0)
- {
- total=total+file[i];}
- }
- average=total/(height*width);
- printf("The average depth of the water is %fm.",average);
- if(average<0)
- {
- r_average=-1*average;
- fprintf(fpio2,"say The average depth of the water is minus %fm.",r_average);
- }
- else
- {
- fprintf(fpio2,"say The average depth of the water is %fm.",average);
- }
- free(file);
- fclose(fpio);
- fclose(fpio2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement