Skip to content

Commit

Permalink
daily upload
Browse files Browse the repository at this point in the history
  • Loading branch information
TGSpock123 committed Dec 21, 2023
1 parent b48ba93 commit 16c8512
Show file tree
Hide file tree
Showing 32 changed files with 271 additions and 47 deletions.
Binary file added 10_plus/.10.25.c.swp
Binary file not shown.
Binary file added 10_plus/10.15
Binary file not shown.
19 changes: 19 additions & 0 deletions 10_plus/10.15.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <stdio.h>
int main (void)
{
int zippo[4][2] =
{
{2, 4}, {6, 8}, {1, 3}, {5, 7}
};

printf (" zippo = %p, zippo + 1 = %p\n", zippo, zippo + 1);
printf ("zippo[0] = %p, zippo[0] + 1 = %p\n", zippo[0], zippo[0] +1);
printf (" *zippo = %p, *zippo + 1 = %p\n", *zippo, *zippo + 1);
printf ("zippo[0][0] = %d\n", zippo[0][0]);
printf ("*zippo[0] = %d\n", *zippo[0]);
printf ("**zippo = %d\n", **zippo);
printf ("zippo[2][1] = %d\n", zippo[2][1]);
printf ("*(*zippo + 2) + 1 = %d\n", *(*(zippo + 2) + 1));

return 0;
}
Binary file added 10_plus/10.16
Binary file not shown.
18 changes: 18 additions & 0 deletions 10_plus/10.16.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <stdio.h>
int main (void)
{
int zippo[4][2] = {{2, 4}, {6, 8}, {1, 3}, {5, 7}};
int (*pz)[2];
pz = zippo;

printf ("pz = %p, pz + 1 = %p\n\n", pz, pz + 1);
printf ("pz[0] = %p, pz[0] + 1 = %p\n\n", pz[0], pz[0] + 1);
printf ("*pz = %p, *pz + 1 = %p\n\n", *pz, *pz + 1);
printf ("pz[0][0] = %d\n", pz[0][0]);
printf ("*pz[0] = %d\n", *pz[0]);
printf ("**pz = %d\n", **pz);
printf ("pz[2][1] = %d\n", pz[2][1]);
printf ("*(*(pz + 2) + 1) = %d\n", *(*(pz + 2) + 1));

return 0;
}
17 changes: 17 additions & 0 deletions 10_plus/10.17.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <stdio.h>
#include "10.17_18.h"
int main (void)
{
int junk[ROWS][COLS] =
{
{2, 4, 6, 8},
{3, 5, 7, 9},
{12, 10, 8, 6}
};

sum_rows (junk, ROWS);
sum_cols (junk, ROWS);
printf ("Sum of all elements = %d\n", sum2d (junk, ROWS));

return 0;
}
Binary file added 10_plus/10.17_18
Binary file not shown.
5 changes: 5 additions & 0 deletions 10_plus/10.17_18.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#define ROWS 3
#define COLS 4
void sum_rows (int ar[][COLS], int rows);
void sum_cols (int ar[][COLS], int rows);
int sum2d (int (*ar)[COLS], int rows);
50 changes: 50 additions & 0 deletions 10_plus/10.18.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include <stdio.h>
#include "10.17_18.h"
void sum_rows (int ar[][COLS], int rows)
{
int r;
int c;
int tot;

for (r = 0; r < rows; r ++)
{
tot = 0;
for (c = 0; c < COLS; c ++)
{
tot += ar[r][c];
}
printf ("row %d: sum = %d\n", r, tot);
}
}
void sum_cols (int ar[][COLS], int rows)
{
int r;
int c;
int tot;

for (c = 0; c < COLS; c ++)
{
tot = 0;
for (r = 0; r < rows; r ++)
{
tot += ar[r][c];
}
printf ("col %d: sum = %d\n", c, tot);
}
}
int sum2d (int ar[][COLS], int rows)
{
int r;
int c;
int tot = 0;

for (r = 0; r < rows; r ++)
{
for (c = 0; c < COLS; c ++)
{
tot += ar[r][c];
}
}

return tot;
}
37 changes: 37 additions & 0 deletions 10_plus/10.19.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <stdio.h>
#include "10.19_20.h"
int main (void)
{
int i, j;
int rs = 3;
int cs = 10;

int junk[ROWS][COLS] =
{
{2, 4, 6, 8},
{3, 5, 7, 9},
{12, 10, 8, 6}
};
int morejunk[ROWS - 1][COLS + 2] =
{
{20, 30, 40, 50, 60, 70},
{5, 6, 7, 8, 9, 10}
};
int varr[rs][cs];

for (i = 0; i < rs; i ++)
{
for (j = 0; j < cs; j ++)
{
varr[i][j] = i * j + j;
}
}
printf ("3 * 5 array\n");
printf ("Sum or all elements = %d\n", sum2d (ROWS, COLS, junk));
printf ("2 * 6 array\n");
printf ("Sum of all elements = %d\n", sum2d (ROWS -1, COLS + 2, morejunk));
printf ("3 * 10 VLA\n");
printf ("Sum of all elements = %d\n", sum2d (rs, cs, varr));

return 0;
}
Binary file added 10_plus/10.19_20
Binary file not shown.
4 changes: 4 additions & 0 deletions 10_plus/10.19_20.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#define ROWS 3
#define COLS 4
int sum2d (int rows, int cols, int ar[rows][cols]);

18 changes: 18 additions & 0 deletions 10_plus/10.20.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <stdio.h>
#include "10.19_20.h"
int sum2d (int rows, int cols, int ar[rows][cols])
{
int r;
int c;
int tot = 0;

for (r = 0; r < rows; r ++)
{
for (c = 0; c < cols; c ++)
{
tot += ar[r][c];
}
}

return tot;
}
19 changes: 19 additions & 0 deletions 10_plus/10.21.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <stdio.h>
#include "10.21_22.h"
int main (void)
{
int total1, total2, total3;
int * pt1;
int(*pt2)[COLS];

pt1 = (int[2]){10, 20};
pt2 = (int[2][COLS]){{1, 2, 3, -9}, {4, 5, 6, -8}};
total1 = sum (pt1, 2);
total2 = sum2d(pt2, 2);
total3 = sum ((int []){4, 4, 4, 5, 5, 5}, 6);
printf ("total1 = %d\n", total1);
printf ("total2 = %d\n", total2);
printf ("total3 = %d\n", total3);

return 0;
}
Binary file added 10_plus/10.21_22
Binary file not shown.
3 changes: 3 additions & 0 deletions 10_plus/10.21_22.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#define COLS 4
int sum2d (const int ar[][COLS], int rows);
int sum (const int ar[], int n);
30 changes: 30 additions & 0 deletions 10_plus/10.22.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <stdio.h>
#include "10.21_22.h"
int sum (const int ar[], int n)
{
int i;
int total = 0;

for (i = 0; i < n; i ++)
{
total += ar[i];
}

return total;
}
int sum2d (const int ar[][COLS], int rows)
{
int r;
int c;
int tot = 0;

for (r = 0; r < rows; r ++)
{
for (c = 0; c < COLS; c ++)
{
tot += ar[r][c];
}
}

return tot;
}
Binary file added 10_plus/10.23
Binary file not shown.
15 changes: 15 additions & 0 deletions 10_plus/10.23.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <stdio.h>
int main (void)
{
int ref[] = {8, 4, 0, 2};
int *ptr;
int index;

printf ("%d\n", *++ref);
for (index = 0; index < 4; index ++, ptr ++)
{
printf ("%d %d %d\n", index, ref[index], *ptr);
}

return 0;
}
Binary file added 10_plus/10.24
Binary file not shown.
16 changes: 16 additions & 0 deletions 10_plus/10.24.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <stdio.h>
int main (void)
{
int * ptr;
int trof[2][2] = {12, 14, 16};
int trof_2[2][2] = {{12}, {14, 16}};

ptr = trof[0];
printf ("*ptr = %d ptr = %p\n", *ptr, ptr);
printf ("*(ptr + 2) = %d ptr + 2 = %p\n", *(ptr + 2), ptr + 2);
ptr = trof_2[0];
printf ("*ptr2 = %d ptr2 = %p\n", *ptr, ptr);
printf ("*(ptr2 + 2) = %d ptr2 + 2 = %p\n", *(ptr + 2), ptr + 2);

return 0;
}
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ set(CMAKE_CXX_STANDARD 14)
include_directories(9)

add_executable(C_primer
10_plus/10.13.c 10_plus/10.14.c 10_plus/10.13_14.h
10_plus/10.23.c
)
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
{
"directoryIndex" : 0,
"id" : "C_primer::@6890427a1f51a3e7e1df",
"jsonFile" : "target-C_primer-Debug-fe2f8957925620870bf8.json",
"jsonFile" : "target-C_primer-Debug-4ba02d12a23351dc7203.json",
"name" : "C_primer",
"projectIndex" : 0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"objects" :
[
{
"jsonFile" : "codemodel-v2-06f5439d6793c55423fd.json",
"jsonFile" : "codemodel-v2-8cc01aa64a5d769a8dbe.json",
"kind" : "codemodel",
"version" :
{
Expand Down Expand Up @@ -86,7 +86,7 @@
},
"codemodel-v2" :
{
"jsonFile" : "codemodel-v2-06f5439d6793c55423fd.json",
"jsonFile" : "codemodel-v2-8cc01aa64a5d769a8dbe.json",
"kind" : "codemodel",
"version" :
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@
"language" : "C",
"sourceIndexes" :
[
0,
1
0
]
}
],
Expand Down Expand Up @@ -89,15 +88,7 @@
"name" : "Source Files",
"sourceIndexes" :
[
0,
1
]
},
{
"name" : "Header Files",
"sourceIndexes" :
[
2
0
]
}
],
Expand All @@ -106,19 +97,8 @@
{
"backtrace" : 1,
"compileGroupIndex" : 0,
"path" : "10_plus/10.13.c",
"sourceGroupIndex" : 0
},
{
"backtrace" : 1,
"compileGroupIndex" : 0,
"path" : "10_plus/10.14.c",
"path" : "10_plus/10.23.c",
"sourceGroupIndex" : 0
},
{
"backtrace" : 1,
"path" : "10_plus/10.13_14.h",
"sourceGroupIndex" : 1
}
],
"type" : "EXECUTABLE"
Expand Down
Binary file modified cmake-build-debug/.ninja_deps
Binary file not shown.
14 changes: 7 additions & 7 deletions cmake-build-debug/.ninja_log
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# ninja log v5
335 503 1702822896535710815 C_primer 5cb5d6dfc54446d4
433 1450 1702958014858365474 C_primer d7434207347cad4d
4 335 1702822896367170007 CMakeFiles/C_primer.dir/9_plus/9_plus/9.36.c.o 9f95dd8b31879556
1 144 1702825381558358062 CMakeFiles/C_primer.dir/10_plus/10.14.c.o 27c11ea85739635
0 267 1702717481449984888 CMakeFiles/C_primer.dir/10_plus/10.12.c.o d0b2887c66daa4b1
0 431 1702958013825178426 CMakeFiles/C_primer.dir/10_plus/10.15.c.o 3cd52d55636f54b
0 305 1702822896335875576 CMakeFiles/C_primer.dir/9_plus/9_plus/9.35.c.o c09ce47479a5514a
1 823 1702825261308715094 CMakeFiles/C_primer.dir/10_plus/10.13.c.o 7bef308e0e43b8ac
3 825 1702825261305992604 CMakeFiles/C_primer.dir/10_plus/10.14.c.o 27c11ea85739635
826 962 1702825261443792962 C_primer a3cbc96ef3d4c1f7
0 110 1702825272983423224 CMakeFiles/C_primer.dir/10_plus/10.13.c.o 7bef308e0e43b8ac
1 138 1702825381555261318 CMakeFiles/C_primer.dir/10_plus/10.13.c.o 7bef308e0e43b8ac
1 144 1702825381558358062 CMakeFiles/C_primer.dir/10_plus/10.14.c.o 27c11ea85739635
144 322 1702825381740197165 C_primer a3cbc96ef3d4c1f7
0 399 1703062779349976926 CMakeFiles/C_primer.dir/10_plus/10.23.c.o 4a833a773a8f433a
403 1098 1703062780055927389 C_primer 81b0a4dcc53c9b5b
1 268 1703062788743730179 CMakeFiles/C_primer.dir/10_plus/10.23.c.o 4a833a773a8f433a
268 702 1703062789201748673 C_primer 81b0a4dcc53c9b5b
Binary file not shown.
2 changes: 1 addition & 1 deletion cmake-build-debug/CMakeFiles/clion-Debug-log.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/Applications/CLion.app/Contents/bin/cmake/mac/x64/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_MAKE_PROGRAM=/Applications/CLion.app/Contents/bin/ninja/mac/x64/ninja -G Ninja -S /Users/tgspock/Documents/GitHub/learn_c_primer.github.io -B /Users/tgspock/Documents/GitHub/learn_c_primer.github.io/cmake-build-debug
-- Configuring done (0.1s)
-- Configuring done (0.3s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/tgspock/Documents/GitHub/learn_c_primer.github.io/cmake-build-debug
Binary file modified cmake-build-debug/C_primer
Binary file not shown.
4 changes: 2 additions & 2 deletions cmake-build-debug/Testing/Temporary/LastTest.log
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Start testing: Dec 17 23:03 CST
Start testing: Dec 20 16:59 CST
----------------------------------------------------------
End testing: Dec 17 23:03 CST
End testing: Dec 20 16:59 CST
Loading

0 comments on commit 16c8512

Please sign in to comment.