Compare commits

..
22 Commits
Author SHA1 Message Date
kevinnls 78e466eb0f use new fname 2021-09-20 16:44:01 +05:30
kevinnls f470cca975 i do not want LABELS or \n after all 2021-09-20 16:34:55 +05:30
kevinnls d6b273453a patch: use old name + fix typo 2021-09-20 16:32:03 +05:30
kevinnls 9b96b077c7 use dprintf() 2021-09-20 16:28:13 +05:30
kevinnls 61101f6166 rename to dprintf() 2021-09-20 16:23:50 +05:30
kevinnls 038f493d19 create debug_msg() 2021-09-20 16:18:45 +05:30
kevinnls 0ff2d37606 rudimentary cli arg support 2021-09-20 10:58:51 +05:30
kevinnls 2804fb5b63 output statements 2021-09-20 10:45:59 +05:30
kevinnls b7a596aa7d create gitignore
more like check in because i forgot to when i created

note: negate gitignore
2021-09-20 10:38:00 +05:30
kevinnls 2079046d46 fix: stop swapping over bounds 2021-09-20 10:34:26 +05:30
kevinnls 621c51d037 for some reason it works this way? 2021-09-20 02:42:01 +05:30
kevinnls f6b854a90b more debug statements 2021-09-20 02:39:42 +05:30
kevinnls 11ab566867 implement basic sorting 2021-09-20 02:31:04 +05:30
kevinnls 110084953e simplify 2021-09-20 02:23:38 +05:30
kevinnls 2818ddaf36 setup for debugging 2021-09-20 02:18:17 +05:30
kevinnls 9b10e5df1e start fleshing out 2021-09-20 01:47:28 +05:30
kevinnls c2375032c6 calculcate size in main because pointers 2021-09-20 01:39:44 +05:30
kevinnls 8a4412e155 trying to understand arrays and pointers 2021-09-20 01:20:58 +05:30
kevinnls 9678b35422 fix setup 2021-09-20 01:09:41 +05:30
kevinnls aa2634dd3f control program to check env
duh~
2021-09-20 01:08:29 +05:30
kevinnls b78c26001d add: readme 2021-03-27 20:25:44 +05:30
kevinnls c21e1568b4 root 2021-03-27 20:23:04 +05:30
9 changed files with 104 additions and 25 deletions

No files matched your search

+6
View File
@@ -0,0 +1,6 @@
**
!.gitignore
!**/
!*.c
!*.h
!*.md
-3
View File
@@ -1,3 +0,0 @@
alias m := make
make TARGET:
make .{{ trim_start_match(invocation_dir(),justfile_dir()) / trim_end_match(TARGET,".c") }}
-3
View File
@@ -1,3 +0,0 @@
%: %.c
cc $< -o $@
-3
View File
@@ -1,3 +0,0 @@
# learning c
following Kernighan and Ritchie's book
+5
View File
@@ -0,0 +1,5 @@
# Learning C
just learning the C language
the code in the repo is not licensed for reuse. but really, there isn't anything for you to use or that isn't already free to use. it's mainly for myself
+1
View File
@@ -0,0 +1 @@
main.c
+10
View File
@@ -0,0 +1,10 @@
#include<stdio.h>
#include<stdlib.h>
#include<stdarg.h>
void debug_msg(char* fmt, ... ){
va_list args;
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
}
+82
View File
@@ -0,0 +1,82 @@
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include "../_headers/debug.h"
int* sort(int*, int);
void swap(int*, int, int);
void integeriseArgs(int, char**, int*);
int DEBUG;
int main(int argc, char** argv){
int arr[argc-1];
integeriseArgs(argc, argv, arr);
char* _debug = getenv("DEBUG");
if(_debug)
DEBUG = !strcmp(_debug,"1");
//how does this even work???
//int arr[] = {1,2,3,5,4};
int arr_len = sizeof(arr) / sizeof(arr[0]);
sort(arr, arr_len);
printf("sorted array: ");
for(int i=0; i<arr_len; i++){
if(i!=0) printf(", ");
printf("%d", arr[i]);
}
printf("\n");
return EXIT_SUCCESS;
}
int* sort(int* arr, int length){
if(DEBUG){
debug_msg("length of array to be sorted: %d\n", length);
debug_msg("elements of array to be sorted: ");
for(int i=0; i<length; i++){
debug_msg("%s%d", i==0?"":", ",arr[i]);
}
debug_msg("\n");
}
int changes = 0;
do {
changes = 0;
for(int i=0; i<length-1; i++){
if(arr[i]>arr[i+1]){
if(DEBUG) debug_msg("need to swap [%d]->%d and [%d]->%d\n",i,arr[i],i+1,arr[i+1]);
swap(arr, i, i+1);
++changes;
}
}
} while (changes != 0);
if(DEBUG){
debug_msg("=====\nelement post-sort are: ");
for(int i=0; i<length; i++){
debug_msg("%s%d", i==0?"":", ",arr[i]);
}
debug_msg("\n");
}
return arr;
}
void swap(int* arr, int left, int right){
if(DEBUG)
debug_msg("PRESWAP left[%d] is: %d; right[%d] is %d\n", left,arr[left],right,arr[right]);
int _hold = arr[left];
arr[left] = arr[right];
arr[right] = _hold;
if(DEBUG)
debug_msg("POSTSWAP left[%d] is: %d; right[%d] is %d\n", left,arr[left],right,arr[right]);
}
void integeriseArgs(int len, char** args, int* arr_ptr){
for(int i=1; i<len ; i++){
arr_ptr[i-1] = atoi(args[i]);
}
}
-16
View File
@@ -1,16 +0,0 @@
#include <stdio.h>
int main(){
int lowerF, upperF, step;
lowerF = 0; upperF = 300;
step = 20;
int fahr, cel;
printf("%s\t%s\n", "°F", "°C");
printf("%s\t%s\n", "===", "===");
for(fahr=lowerF; fahr<=upperF; fahr+=step){
cel = 5 * (fahr - 32) / 9;
printf("%3d\t%3d\n", fahr, cel);
}
}