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 / sorted_vector.cpp
Last active January 21, 2017 05:02
An example of a class that enforces sorting on a vector.
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <iostream>
template<typename T>
struct comparator
{
bool operator()(const T & a, const T & b)
{
@muaddib1971
muaddib1971 / array_func.c
Created January 15, 2017 19:55
example of passing an array to a function in c
#include <stdio.h>
#include <stdlib.h>
int doit(int array[])
{
int i;
int sum=0;
for(i = 0; i < 10 ; ++i)
{
sum += array[i];
@muaddib1971
muaddib1971 / timemax.c
Created January 15, 2017 22:51
program to calculate the largest year representable on a 64 bit system.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#define ONE_YEAR 60*60*24*366
int main(void)
{
time_t now = 67767751872000000l;
for(;;)
{
@muaddib1971
muaddib1971 / err_message.c
Created January 21, 2017 05:01
A program that takes an error number and outputs the correct error message that matches it.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#define ONE_ARG 2
#define DECIMAL 10
typedef enum { FALSE, TRUE } BOOLEAN;
@muaddib1971
muaddib1971 / utility.c
Created January 23, 2017 04:23
example of a file that the "file" command on redhat classifies as a pascal rather than a c file.
#include "utility.h"
/**
* this function is required for buffer clearing. It simply removes all
* characters from the input buffer. Note: you should only call this when
* you detect buffer overflow.
**/
void read_rest_of_line(void)
{
int ch;
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
int main(void)
{
FILE * fp = fopen("foo", "r");
if(!fp)
{
@muaddib1971
muaddib1971 / .vimrc
Last active March 16, 2017 02:38
My vimrc file that I use by default on all systems
syntax on
set autoindent
set smartindent
set ts=4 sw=4 et si
set whichwrap +=<,>,[,]
set backspace=indent,eol,start
set hlsearch
set number
set mouse=a
"set foldmethod=syntax
@muaddib1971
muaddib1971 / moveit.cpp
Last active March 25, 2017 01:08
An example of moving from a const reference and what that does to the original variable
#include <string>
#include <iostream>
#include <cstdlib>
void moveit(std::string& s)
{
std::string mys = std::move(s);
}
int main(void)
#include <stdio.h>
#include <stdlib.h>
int warning(){}
int main(void)
{
printf("%d\n", warning());
return EXIT_SUCCESS;
}
#include <stdio.h>
#include <stdlib.h>
void doit(void)
{
int array[4] = {0};
int i;
for(i = 0; i <= 20; i++)
{
array[i]-=8;