Skip to content

Instantly share code, notes, and snippets.

@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
};
@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 / 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;
}
}
#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 / 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;
}