home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_08_11
/
8n11102a
< prev
next >
Wrap
Text File
|
1990-08-09
|
1KB
|
49 lines
*********
Listing 2
#include <stdio.h>
typedef int MAT[4][4];
main()
{
MAT matA, matB;
int i, j, fd, n = 4;
char *cptr;
puts("\014\n\n ENTER MATRIX ROW BY ROW");
for (i = 0; i < n; ++i)
for(j = 0; j < n; ++j)
scanf("%d", &matA[i][j]);
fd = creat("mats.data",4);
cptr = matA; /*no cast -- even tho the scalar of matA is 32 */
write(fd, cptr, sizeof(MAT)); /* cptr is taken to be the
pointer to an array of 32 char */
close(fd);
fd = open("mats.data",2);
cptr = matB; /* cptr now points to the other matrix -- no
cast */
read(fd, cptr, sizeof(MAT));
close(fd);
puts("\n\n\n");
for (i = 0; i < n; ++i)
{
for (j = 0; j < n; ++j) /* 4 x 4 matrix of */
printf("%4d", matB[i][j]); /* integers is
output */
putchar('\n'); /* to screen */
}
}