Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <unistd.h>
- #include <fcntl.h>
- #include <stdio.h>
- int main(int argc, char * argv[])
- {
- if (argc!=2)
- {
- //printf (“Usage: mpproc np <pathname1> <a|s|m|T> [pathname2] <pathname3> \n”);
- printf ("Usage: mpproc <pathname1> \n");
- exit(1);
- }
- float rows, cols;
- int i,j;
- float matrix[8][8];
- FILE *file = fopen(argv[1], "r");
- //Read Matrix
- if ( file )
- {
- if ( fread(&rows, sizeof (float),1,file ) == 1 &&
- fread(&cols,sizeof (float),1, file ) == 1 )
- {
- for (i = 0; i<rows;i++)
- {
- for (j=0; j<cols;j++)
- {
- float value;
- if (fread (&value, sizeof (float),1, file) == 1)
- {
- matrix [i][j] = value;
- }
- else break;
- }
- }
- }
- else
- {
- printf("Sorry, incorrect format. \n");
- }
- fclose(file);
- }
- else
- {
- printf("Error: Cannot open file. \n");
- }
- //Display Matrix
- printf("Rows: %f ; Cols: %f \n",rows,cols);
- for (i = 0; i<rows;i++)
- {
- printf("| ");
- for (j=0; j<cols;j++)
- {
- printf(" %f ", matrix[i][j]);
- }
- printf(" |\n");
- }
- exit (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement