From 9e2059bd535eba7a67e8a5c8909bdc45d140f0e9 Mon Sep 17 00:00:00 2001 From: GAMihov18 <23IMC10627@imc.ac.at> Date: Sun, 1 Dec 2024 14:35:35 +0100 Subject: [PATCH] Finish assignment --- .vscode/tasks.json | 28 +++++++++++++++++++++++ assignment | Bin 0 -> 16368 bytes assignment.c | 55 +++++++++++++++++++++++++++++++++++++++++++-- matrix.txt | 5 +++++ test | Bin 0 -> 16408 bytes 5 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 .vscode/tasks.json create mode 100755 assignment create mode 100644 matrix.txt create mode 100755 test diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..08d9005 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,28 @@ +{ + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: gcc build active file", + "command": "/usr/bin/gcc", + "args": [ + "-fdiagnostics-color=always", + "-g", + "${file}", + "-o", + "${fileDirname}/${fileBasenameNoExtension}" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "Task generated by Debugger." + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/assignment b/assignment new file mode 100755 index 0000000000000000000000000000000000000000..0f697267cdf3444fb55cade71fb977cf4d60fbd9 GIT binary patch literal 16368 zcmeHOYiu0V6~1db#DTDO2mvRQcnA(kAfDK<<2pcKcVjzaYm=D72~7)3#=EoLE&F12 zHrNzVg9&A2Ox+?%kZ2Y7Q=}GQwN#>&04Ib1EiEDHk5pAti;}W#c$h*_piQ>t%-l0O zJM7X5_3>w}we#KcoyWa%=HWXt_kOcG*i+^4Fe=sTI)>8dVw3T4MN22I0QguZJ0G@< zY&kmzLDWfRVu^00YX-9TB6@Pta90j zBRnV}>8JALb_7Y^YguV<|q#^D@Pe{7^){VeU7~{RroHdxVrv z>^}ZFc|M)k0y->&PQNJkb7Gh2#t5+uEIUr>;V;r&KljTEMi}PA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h9JPb`*eQ!YPOU99Iyc-d@O$@aLek_n*cags;+p;X%lcV!q(;r*R%3J@=Bm zGk-5}f2$dRTXHx&J*njfR3#Nv!-4v~@v;E(L#_lg%W||T@uODao*gu%d zYFvZpNze1NKGkVYGT{f{Q)lz1b#G~W0D?kxrc{)P$7#NJ?$UEEJy+0rV_H{?*B=)0 zqvQA^;Bf!RpPu)lYtb6Motj{6$)E5XaJKt1A2)3=k=mgEWr}1k&_jlT3 zTlTVux6jQj75QIbF=mDQ?MUa2-L#Vj?B^%UrJ#hT11o=cFTt_^e$;n^;G6sTi8t;D XPVJH{4)4qPFaEM=vCQG%5ZONgIxE}$ literal 0 HcmV?d00001 diff --git a/assignment.c b/assignment.c index 653791d..9ace8fa 100644 --- a/assignment.c +++ b/assignment.c @@ -10,9 +10,60 @@ int main(int argc, char *argv[]) { srand(time(NULL)); int minrand = 1; int maxrand = 100; + size_t arraySize[2]; - // WRITE YOUR CODE HERE - + if (argc != 3) + { + printf("Incorrect usage. You provided n arguments. The correct number of arguments is 2\n"); + return 1; + } + int converted; + for (size_t i = 1; i < (size_t)argc; i++) + { + converted = atoi(argv[i]); + if (converted<=0) + { + printf("Incorrect usage. The parameters you provided are not positive integers\n"); + return 1; + } + arraySize[i-1] = converted; + } + int **array = (int **)malloc(arraySize[0] * sizeof(int *)); + if (array == NULL) + { + printf("Memory allocation failed\n"); + return 1; + } + + for (size_t i = 0; i < arraySize[0]; i++) + { + array[i] = (int *)malloc(arraySize[1] * sizeof(int)); + if (array[i] == NULL) + { + printf("Memory allocation failed\n"); + return 1; + } + for (size_t j = 0; j < arraySize[1]; j++) + { + array[i][j] = (rand() % (maxrand - minrand + 1)) + minrand; + } + } + FILE *file = fopen("matrix.txt", "w"); + if (file == NULL) { + printf("Error: Could not open file.\n"); + return 1; + } + for (size_t i = 0; i < arraySize[0]; i++) + { + for (size_t j = 0; j < arraySize[1]; j++) + { + fprintf(file, "%d ", array[i][j]); + } + fprintf(file, "\n"); + free(array[i]); + } + free(array); + fclose(file); return 0; } diff --git a/matrix.txt b/matrix.txt new file mode 100644 index 0000000..6702981 --- /dev/null +++ b/matrix.txt @@ -0,0 +1,5 @@ +67 24 92 82 28 45 64 4 37 33 +47 79 39 22 81 44 32 18 27 65 +38 57 38 88 84 74 62 64 16 69 +80 82 44 23 16 72 19 79 75 7 +63 74 85 2 95 17 97 78 86 24 diff --git a/test b/test new file mode 100755 index 0000000000000000000000000000000000000000..3e23a3c0532a77e32f3f5c35b8adfd70d833315d GIT binary patch literal 16408 zcmeHOeQX@X6`wmN#FQjL6BPI2%CxAsh*oYTM5;=a)duRSs<=Q&0&S^-N|mY-jnYQCQz$j!qv0#p_h#R_ z+gt8vX)E=gd(!Qj_j?~R^LBP`c6a81(ALetKtM3niS+`d>>L+qCB+xlPytx0SR-b^ zaj{q=E&_R)#9V!=%RuYWsbD#;C%g_g`pw5e1%8za3+CKHXE9c{smkHwRha&nV$uCKM%%`Y6 z=A2K=3I5hlKK*S zFfacu@oC;g^;J6$W0Zg9lwPqsYIUz}Sso2HMXh+czo~!C>Za8#YAT^N%O+sE6!_t= z*|NP;K$t9IltvNU=gJ%pb#qCN_MIE9XnQ&Jmm7CK*u1xEVrJjdHye+l4YnJ7&;|+P z@en~7%Xn#`jhm0JLCM9CpEO^JA+JVPfa1~$%2ieH#{gF<*kk>b;&fNRv8|Qttt$Ao zDtM?0{xskU{QR^8fJ*h=SOv%XO(px!RKcGIT!EjTwgXTp&Thc5O&_6T+DQprPdP@< z-Fi>tZoSvAqN3L}P0^c3nsMP+F;f^$!V)nf8cp|62o3yRC(<@T8 z5f6jDr{B^j(L@RuRMaET69@BZv1Mz=rZ&AB)rC$_IYr;PcR+y;Pe+J zRU;nUy-&CvqaGaVU>ft_oD0+)_TZ4{B8_|SONyuv6CQk~2hVzNIH5&4;lXDYQTRXg z;5-&Q>RPdufm#M?8K`BTmVsIZ{)-H}*|6w6ZSb{vEi?U(%Z1PmWSwAPQXBkL{c|#E z;igRh7nZiev0-tm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