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,66 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct node {
char* name;
struct node* next;
};
struct node* add(struct node* head, char* name) {
struct node* n;
struct node* p;
n = (struct node*)malloc(sizeof(struct node));
n->name = (char*)malloc(strlen(name)+1);
strcpy(n->name, name);
n->next = NULL;
if(head == NULL) {
return n;
}
p = head;
while(p->next != NULL) {
p = p->next;
}
p->next = n;
return head;
}
int known(struct node* head, char *name) {
struct node* p;
p = head;
while(p != NULL && strcmp(p->name, name) != 0) {
p = p->next;
}
return p != NULL;
}
void clear(struct node* head) {
if(head == NULL) {
return;
}
clear(head->next);
free(head->name);
free(head);
}
int main(int argc, char** argv) {
char name[64];
struct node* head=NULL;
while(scanf("%s", name) == 1) {
if(known(head, name)) {
printf("Still around %s, eh?\n", name);
}
else {
head = add(head, name);
printf("Hello %s\n", name);
}
}
clear(head);
return 0;
}
@@ -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;
}
@@ -0,0 +1,38 @@
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char** argv) {
FILE* f;
int rows, cols, i, j;
int** m;
f = fopen(argv[1], "r");
if(f == NULL) {
perror("Nu am putut deschide fisierul cu matricea");
return 1;
}
fscanf(f, "%d %d", &rows, &cols);
m = (int**)malloc(rows*sizeof(int*));
for(i=0; i<rows; i++) {
m[i] = (int*)malloc(cols*sizeof(int));
for(j=0; j<cols; j++) {
fscanf(f, "%d",&m[i][j]);
}
}
fclose(f);
for(i=0; i<rows;i++) {
for(j=0; j<cols; j++) {
printf("%2d ", m[i][j]);
}
printf("\n");
}
for(i=0; i<rows; i++) {
free(m[i]);
}
free(m);
return 0;
}
@@ -0,0 +1,47 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc, char** argv) {
int** m;
FILE* f;
int i, j, rows, cols, fd;
f = fopen(argv[1], "r");
if(f == NULL) {
perror("Could not open file");
return 1;
}
fscanf(f, "%d %d", &rows, &cols);
m = (int**)malloc(sizeof(int*)*rows);
for(i=0; i<rows; i++) {
m[i] = (int*)malloc(sizeof(int)*cols);
for(j=0; j<cols; j++) {
fscanf(f, "%d",&m[i][j]);
}
}
fclose(f);
fd = open(argv[2], O_CREAT | O_WRONLY, 00600);
if(fd == -1) {
perror("Could not open destination file");
return 1;
}
write(fd, &rows, sizeof(int));
write(fd, &cols, sizeof(int));
for(i=0; i<rows; i++) {
for(j=0; j<cols; j++) {
write(fd, &m[i][j], sizeof(int));
}
}
close(fd);
for(i=0;i<rows;i++)
{
free(m[i]);
}
free(m);
return 0;
}
@@ -0,0 +1,9 @@
7 3
1 2 3
4 5 6
7 8 9
10 11 12
13 14 15
16 17 18
19 20 21
@@ -0,0 +1,9 @@
Joe
Ann
John
Mary
Mike
Pam
Joe
Pam
Mike