Advertisement
Kojima0502

averave_raw_voice

Dec 10th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.95 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main(int argc,char *argv[])
  6. {
  7.     FILE *fpio;
  8.     FILE *fpio2;
  9.     int i,height,width;
  10.     float *file;
  11.     //float *file3;
  12.     //float start,end;
  13.     float total,average;
  14.     float r_average;
  15.    
  16.     if(argc!=5)
  17.     {
  18.         fprintf(stderr,"Usage: %s\n(2)Input_R_READ_filename\n(3)width\n(4)height\n(5)output_filename",argv[0]);
  19.         exit(1);
  20.     }
  21.    
  22.     printf("Input FILE NAME:%s\n",argv[1]);
  23.     printf("output file name:%s\n",argv[2]);
  24.    
  25.    
  26.     width = atoi(argv[2]); printf("W = %d,", width);
  27.     height = atoi(argv[3]); printf("H = %d\n", height);
  28.    
  29.     /*---------ÉÅÉÇÉäÇÃé©ìÆäÑìñ----------*/
  30.     file= (float *)malloc(width*height*sizeof(float));
  31.    
  32.     /*----------------ì¸óÕRâÊëúÉtÉ@ÉCÉãÇÃÉIÅ[ÉvÉìäJén----------------------*/
  33.     if((fpio=fopen(argv[1],"rb"))==NULL)
  34.     {       /*ÉtÉ@ÉCÉãÇÃÉIÅ[ÉvÉì*/
  35.         fprintf(stderr,"input file open error\n");
  36.         exit(1);
  37.     }
  38.    
  39.     fread((float *)file,sizeof(float),width*height,fpio);
  40.     /*----------------âÊëúÉtÉ@ÉCÉãÇÃÉIÅ[ÉvÉìèIóπ----------------------*/
  41.     /*----------------ì¸óÕNIRâÊëúÉtÉ@ÉCÉãÇÃÉIÅ[ÉvÉìäJén----------------------*/
  42.    
  43.     //fread((float *)file3,sizeof(float),width*height,fpo);
  44.    
  45.     if((fpio2=fopen(argv[4],"w"))==NULL)
  46.     {       /*ÉtÉ@ÉCÉãÇÃÉIÅ[ÉvÉì*/
  47.         fprintf(stderr,"input file open error\n");
  48.         exit(1);
  49.     }
  50.    
  51.     total=0;
  52.    
  53.     for(i=0;i<height*width;i++)
  54.     {
  55.         if(file[i]<0)
  56.         {
  57.             total=total+file[i];}
  58.     }
  59.    
  60.     average=total/(height*width);
  61.     printf("The average depth of the water is %fm.",average);
  62.    
  63.     if(average<0)
  64.     {
  65.         r_average=-1*average;
  66.         fprintf(fpio2,"say The average depth of the water is minus %fm.",r_average);
  67.     }
  68.     else
  69.     {
  70.         fprintf(fpio2,"say The average depth of the water is %fm.",average);
  71.     }
  72.    
  73.     free(file);
  74.    
  75.     fclose(fpio);
  76.     fclose(fpio2);
  77.    
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement