Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.06 KB | None | 0 0
  1. #include <unistd.h>
  2. #include <fcntl.h>
  3. #include <stdio.h>
  4.  
  5. int main(int argc, char * argv[])
  6. {
  7.    
  8.     if (argc!=2)
  9.     {
  10.         //printf (“Usage: mpproc np <pathname1> <a|s|m|T> [pathname2] <pathname3> \n”);
  11.         printf ("Usage: mpproc <pathname1> \n");
  12.         exit(1);
  13.     }
  14.    
  15.     float rows, cols;
  16.     int i,j;
  17.    
  18.     float matrix[8][8];
  19.     FILE *file = fopen(argv[1], "r");
  20.     //Read Matrix
  21.     if ( file )
  22.     {
  23.         if ( fread(&rows, sizeof (float),1,file ) == 1 &&
  24.             fread(&cols,sizeof (float),1, file ) == 1 )
  25.         {
  26.             for (i = 0; i<rows;i++)
  27.             {
  28.                 for (j=0; j<cols;j++)
  29.                 {
  30.                     float value;
  31.                     if (fread (&value, sizeof (float),1, file) == 1)
  32.                     {
  33.                         matrix [i][j] = value;
  34.                     }
  35.                     else break;
  36.                 }
  37.             }
  38.         }
  39.         else
  40.         {
  41.             printf("Sorry, incorrect format. \n");
  42.         }
  43.         fclose(file);
  44.     }
  45.     else
  46.     {
  47.         printf("Error: Cannot open file. \n");
  48.     }
  49.     //Display Matrix
  50.     printf("Rows: %f ; Cols: %f \n",rows,cols);
  51.     for (i = 0; i<rows;i++)
  52.     {
  53.         printf("| ");
  54.         for (j=0; j<cols;j++)
  55.         {
  56.             printf(" %f ", matrix[i][j]);
  57.         }
  58.         printf(" |\n");
  59.     }
  60.     exit (0);
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement