Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions assignment8.txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
```C
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4
5 int main(int argc, char **argv)
6 {
7 if (argc != 3) {
8 printf("usage: %s <arg1> <arg2>\n", argv[0]);
9 return 1;
10 }
11
12 char *a = *++argv; /* gets first argument */
13 char *b = *++argv; /* gets second argument */
14 char c[2] = { 0, 0 };
15 char *p;
16 char *q;
17
18 for (p = a; *p; p++) { /* loop until the end of the first arg */
19 if (’a’ <= *p && *p <= ’z’) /* If the first arg is a lowercase letter */
20 *c = *p + ’A’ - ’a’; /* store the capitalized version in c[0] */
21 else
22 *c = *p; /* otherwise store it in c[0] */
23 printf("%s", c); /* print out c[0] with no newline*/
24 }
/* lines 18 to 24 print out the first arg capitalized */
25
26 p = (char *)malloc(strlen(a) + strlen(b) + 1); /* allocate memory for an array big enough to store first and second arg and \0 */
/* also, reassigns p */
27 strcpy(p, a); /* copies a to P */
28 q = p + strlen(a); /* moves q to the \0 of the first arg */
29 while ((*q++ = *b++) != 0)
30 ; /* copies the second arg to after the first arg in p */
31 printf("%s\n", p); /* prints the first arg followed by the second arg (no space) and then a newline */
32 p = NULL; /* reassigns P AGAIN */
33 return 0;
34 }
```
line 23 outputs
Line 31 outputs

line 26 leaks memory
line 32 leaks memory

1) ABCabc123
2) 7 (because the pointer will be deallocated, but the memory it points to will not be)
3) NONE
4) 32 free(p);
47 changes: 47 additions & 0 deletions sort.c
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
/* Harry Brickner
Generates an array and then sorts it */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void bubbleSort(int array[], unsigned int length, int ascending){
for(int loops = 1; loops < length; loops++){
for(int i = 0; i < length - loops; i++){
if((array[i] > array[i + 1]) == ascending){
int temp = array[i];
array[i] = array[i + 1];
array[i + 1] = temp;
}
}
}
}

int main(){
printf("How long should the array be?\n");
unsigned int length;
scanf("%u", &length);
int* unsorted = malloc(length * sizeof(int));
int* ascending = malloc(length * sizeof(int));
int* descending = malloc(length * sizeof(int));
srand(time(0));
for(int i = 0; i < length; i++){
unsorted[i] = rand() % 100;
ascending[i] = unsorted[i];
descending[i] = unsorted[i];
}
bubbleSort(ascending, length, 1);
bubbleSort(descending, length, 0);
for(int i = 0; i < length; i++)
printf("%d ", unsorted[i]);
printf("\n");
for(int i = 0; i < length; i++)
printf("%d ", ascending[i]);
printf("\n");
for(int i = 0; i < length; i++)
printf("%d ", descending[i]);
printf("\n");
free(unsorted);
free(ascending);
free(descending);
return 0;
}
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions assignment8.txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
```C
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4
5 int main(int argc, char **argv)
6 {
7 if (argc != 3) {
8 printf("usage: %s <arg1> <arg2>\n", argv[0]);
9 return 1;
10 }
11
12 char *a = *++argv; /* gets first argument */
13 char *b = *++argv; /* gets second argument */
14 char c[2] = { 0, 0 };
15 char *p;
16 char *q;
17
18 for (p = a; *p; p++) { /* loop until the end of the first arg */
19 if (’a’ <= *p && *p <= ’z’) /* If the first arg is a lowercase letter */
20 *c = *p + ’A’ - ’a’; /* store the capitalized version in c[0] */
21 else
22 *c = *p; /* otherwise store it in c[0] */
23 printf("%s", c); /* print out c[0] with no newline*/
24 }
/* lines 18 to 24 print out the first arg capitalized */
25
26 p = (char *)malloc(strlen(a) + strlen(b) + 1); /* allocate memory for an array big enough to store first and second arg and \0 */
/* also, reassigns p */
27 strcpy(p, a); /* copies a to P */
28 q = p + strlen(a); /* moves q to the \0 of the first arg */
29 while ((*q++ = *b++) != 0)
30 ; /* copies the second arg to after the first arg in p */
31 printf("%s\n", p); /* prints the first arg followed by the second arg (no space) and then a newline */
32 p = NULL; /* reassigns P AGAIN */
33 return 0;
34 }
```
line 23 outputs
Line 31 outputs

line 26 leaks memory
line 32 leaks memory

1) ABCabc123
2) 7 (because the pointer will be deallocated, but the memory it points to will not be)
3) NONE
4) 32 free(p);
47 changes: 47 additions & 0 deletions sort.c
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
/* Harry Brickner
Generates an array and then sorts it */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void bubbleSort(int array[], unsigned int length, int ascending){
for(int loops = 1; loops < length; loops++){
for(int i = 0; i < length - loops; i++){
if((array[i] > array[i + 1]) == ascending){
int temp = array[i];
array[i] = array[i + 1];
array[i + 1] = temp;
}
}
}
}

int main(){
printf("How long should the array be?\n");
unsigned int length;
scanf("%u", &length);
int* unsorted = malloc(length * sizeof(int));
int* ascending = malloc(length * sizeof(int));
int* descending = malloc(length * sizeof(int));
srand(time(0));
for(int i = 0; i < length; i++){
unsorted[i] = rand() % 100;
ascending[i] = unsorted[i];
descending[i] = unsorted[i];
}
bubbleSort(ascending, length, 1);
bubbleSort(descending, length, 0);
for(int i = 0; i < length; i++)
printf("%d ", unsorted[i]);
printf("\n");
for(int i = 0; i < length; i++)
printf("%d ", ascending[i]);
printf("\n");
for(int i = 0; i < length; i++)
printf("%d ", descending[i]);
printf("\n");
free(unsorted);
free(ascending);
free(descending);
return 0;
}
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions assignment8.txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
```C
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4
5 int main(int argc, char **argv)
6 {
7 if (argc != 3) {
8 printf("usage: %s <arg1> <arg2>\n", argv[0]);
9 return 1;
10 }
11
12 char *a = *++argv; /* gets first argument */
13 char *b = *++argv; /* gets second argument */
14 char c[2] = { 0, 0 };
15 char *p;
16 char *q;
17
18 for (p = a; *p; p++) { /* loop until the end of the first arg */
19 if (’a’ <= *p && *p <= ’z’) /* If the first arg is a lowercase letter */
20 *c = *p + ’A’ - ’a’; /* store the capitalized version in c[0] */
21 else
22 *c = *p; /* otherwise store it in c[0] */
23 printf("%s", c); /* print out c[0] with no newline*/
24 }
/* lines 18 to 24 print out the first arg capitalized */
25
26 p = (char *)malloc(strlen(a) + strlen(b) + 1); /* allocate memory for an array big enough to store first and second arg and \0 */
/* also, reassigns p */
27 strcpy(p, a); /* copies a to P */
28 q = p + strlen(a); /* moves q to the \0 of the first arg */
29 while ((*q++ = *b++) != 0)
30 ; /* copies the second arg to after the first arg in p */
31 printf("%s\n", p); /* prints the first arg followed by the second arg (no space) and then a newline */
32 p = NULL; /* reassigns P AGAIN */
33 return 0;
34 }
```
line 23 outputs
Line 31 outputs

line 26 leaks memory
line 32 leaks memory

1) ABCabc123
2) 7 (because the pointer will be deallocated, but the memory it points to will not be)
3) NONE
4) 32 free(p);
47 changes: 47 additions & 0 deletions sort.c
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
/* Harry Brickner
Generates an array and then sorts it */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void bubbleSort(int array[], unsigned int length, int ascending){
for(int loops = 1; loops < length; loops++){
for(int i = 0; i < length - loops; i++){
if((array[i] > array[i + 1]) == ascending){
int temp = array[i];
array[i] = array[i + 1];
array[i + 1] = temp;
}
}
}
}

int main(){
printf("How long should the array be?\n");
unsigned int length;
scanf("%u", &length);
int* unsorted = malloc(length * sizeof(int));
int* ascending = malloc(length * sizeof(int));
int* descending = malloc(length * sizeof(int));
srand(time(0));
for(int i = 0; i < length; i++){
unsorted[i] = rand() % 100;
ascending[i] = unsorted[i];
descending[i] = unsorted[i];
}
bubbleSort(ascending, length, 1);
bubbleSort(descending, length, 0);
for(int i = 0; i < length; i++)
printf("%d ", unsorted[i]);
printf("\n");
for(int i = 0; i < length; i++)
printf("%d ", ascending[i]);
printf("\n");
for(int i = 0; i < length; i++)
printf("%d ", descending[i]);
printf("\n");
free(unsorted);
free(ascending);
free(descending);
return 0;
}