School Commit Init

This commit is contained in:
2024-08-31 12:07:21 +03:00
commit 0b130ee18c
2801 changed files with 4720552 additions and 0 deletions
@@ -0,0 +1,50 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc, char** argv) {
int fd, rows, cols, i, j;
int** m;
if(argc <= 1) {
fprintf(stderr, "No input file specified");
exit(1);
}
fd = open(argv[1], O_RDONLY);
if(fd == -1) {
perror("Failed to open input file");
exit(1);
}
if(read(fd, &rows, sizeof(int)) <= 0) {
perror("Could not read the number of rows");
exit(1);
}
if(read(fd, &cols, sizeof(int)) <= 0) {
perror("Could not read the number of columns");
exit(1);
}
m = (int**)malloc(sizeof(int*)*rows);
for(i=0; i<rows; i++) {
m[i] = (int*)malloc(sizeof(int)*cols);
read(fd, m[i], sizeof(int)*cols);
for(j=0; j<cols; j++) {
printf("%2d" , m[i][j]);
}
printf("\n");
}
for(i=0;i<rows;i++){
free(m[i]);
}
free(m);
close(fd);
return 0;
}