Skip to content

Instantly share code, notes, and snippets.

@iamarkdev
iamarkdev / htoi.c
Created December 1, 2016 11:22
Hex string to integer
#include <stdio.h>
long hexToInt(char hexString[]) {
long result = 0;
for (int i = 0; hexString[i] != '\0'; i++) {
if ((hexString[i] == '0' && hexString[i + 1] == 'x') || hexString[i] == 'x') {
continue;
}
#include <stdio.h>
// remove all characters in string[] that occur in remove[]
void squeeze(char string[], char remove[]) {
int i, x;
for (i = x = 0; string[i] != '\0'; i++) {
int removeChar = 0;
for (int j = 0; remove[j] != '\0'; j++) {
@iamarkdev
iamarkdev / any.c
Last active December 1, 2016 12:14
#include <stdio.h>
// return the index of the first occurrence of any character in matching occuring in string. -1 if none.
int any(char string[], char matching[]) {
for (int i = 0; string[i] != '\0'; i++) {
for (int j = 0; matching[j] != '\0'; j++) {
if (string[i] == matching[j]) {
return i;
}
}
@iamarkdev
iamarkdev / expansion.c
Last active December 4, 2016 08:04
Expand shorthand inputs (I.E a-z becomes a b c d ... x y z, etc)
#include <stdio.h>
int main() {
int c;
char line[] = "";
for (int i = 0; (c = getchar()) != EOF; i++) {
line[i] = c;
if (c == '\n') {
@iamarkdev
iamarkdev / scientificAToF.c
Last active December 5, 2016 05:31
ATOF with support for scientific notation
#include <stdio.h>
#define MAX_LINE_LENGTH 100
enum PositionState {
POSITION_STATE_WHOLE,
POSITION_STATE_DECIMAL,
POSITION_STATE_NOTATION
};
#include <stdio.h>
int main() {
int test[100];
int *testP = test;
while (1) {
printf("%c, %p\n", testP);
//*testP = 0; // This will segfault, however reading does not?..
testP++;
@iamarkdev
iamarkdev / strend.c
Last active December 8, 2016 02:10
Returns 1 if string c occurs at the end of string s
#include <stdio.h>
int mystrend(char *s, char *c) {
int sLen = 0;
int cLen = 0;
while (*s != '\0') {
s++, sLen++;
}
@iamarkdev
iamarkdev / dictgen.c
Last active December 11, 2016 08:35
Being ran with: cc main.c -ldictgen_c; ./a.out ~/Desktop
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <dirent.h>
#include <dictionary_c.h>
#define DICT_MAX_SIZE_BYTES 1024 * 1024 * 32
#define DICT_MIN_PATTERN_SIZE_BYTES 2
#define DICT_STOP_SYMBOL '\0'
#define DICT_MAX_AUTOMATON_SIZE_BYTES 2 << 30
function VehicleConstructor(name) {
var vehicle = {};
//Properties
vehicle.name = name;
vehicle.milesTravelled = 0;
vehicle.maxPassengers = 0;
vehicle.currentPassengers = 0;
// Default Assignments
/*
Preface:
I'm issuing this challenge as I've hit a major roadblock in the development process
of one of my personal side projects. I've spent the last 2 weeks exhaustively exploring
solutions to the following problem and I'm at my wits end. I've taken a number of approaches
using various tree data structures and clever algorithms with no success.