Skip to content

Instantly share code, notes, and snippets.

View muaddib1971's full-sized avatar

Paul Miller muaddib1971

  • RMIT University
View GitHub Profile
@muaddib1971
muaddib1971 / recur.c
Created September 1, 2022 04:56
recursion for brearne
#include <stdio.h>
void recur() {
printf("me: what's the topic, brearne: recursion");
recur();
}
int main() { recur(); }
#include <stdio.h>
#include <stdlib.h>
struct pair {
int first, second;
};
void printpair(const struct pair* apair) {
printf("first: %d, second: %d\n", apair->first, apair->second);
}
@muaddib1971
muaddib1971 / example.c
Created August 15, 2022 07:24
pointer example
#include <stdio.h>
#include <stdlib.h>
#define ADDRESSOF(X) &(X)
#define CONTENTSOF(X) *(X)
void swap(int* a, int* b) {
int temp = *a;
*a = *b;
*b = temp;
#include <stdio.h>
#include <stdlib.h>
/* global variable - you should avoid these especially
* with parallel programming as they are hard to debug
*/
int i = 42;
void printptr(void *ptr) {
/* prints the size of a pointer followed by its address. You
@muaddib1971
muaddib1971 / Makefile.advanced
Last active July 28, 2022 07:56
examples of fgets and the issues it has as well as example Makefiles
#target: prereqs
# command
CFLAGS=-Wall -Werror -std=gnu99
LDFLAGS=-lm
CC=gcc
SOURCES=fooimp.c something.c
HEADERS=fooimp.h
OBJS=fooimp.o something.o
start,clear
store C
IF, LOAD A
skipcond 400 / skip next line if ac is 0
jump mult
quit, load C
output
halt
mult, load C
ADD B
for file in *.zip ; do
#remove the .zip extension from the file name
bfile=$(basename "$file" .zip)
#extract the band name. As the band name is the first part of the file,
#there might be trailing spaces so use sed to remove those
BAND=$(echo "$bfile" | cut -d- -f1 | sed 's/ $//');
#the second part of the file name after the dash is the album name
#there might be spaces before / after the band name so use sed to
#remove those.
#in either case, spaces within the band or album name are left untouched.
@muaddib1971
muaddib1971 / oldenums.cpp
Created March 22, 2022 01:08
newenums.cpp
#include <iostream>
enum class weekdays { MON, TUE, WED, THU, FRI, SAT, SUN };
const std::string daynames[] = {"monday", "tuesday", "wednesday", "thursday",
"friday", "saturday", "sunday"};
#define WEEKLENGTH 7
int main() {
for (int iter = 0; iter < WEEKLENGTH; iter++) {
std::cout << daynames[iter] << '\n';
switch (weekdays(iter)) {
#!/bin/bash
tease() {
echo "echo no, you can't do that"
echo "ha ha"
}
trap tease SEGV
trap tease INT
trap tease KILL
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define ERROR -1
int main(int argc, char **argv) {
int ch;
int hasa = 0, hasb = 0, hasc = 0;
const char *barg = NULL;
while (ch = getopt(argc, argv, "ab:c"), ch != ERROR) {