Skip to content

Instantly share code, notes, and snippets.

@Aenigma
Last active August 29, 2015 14:01
Show Gist options
  • Save Aenigma/eed110761cca2177ab8e to your computer and use it in GitHub Desktop.
Save Aenigma/eed110761cca2177ab8e to your computer and use it in GitHub Desktop.
/*
* Reads from a file and reads out a field in a hardcoded position
*
* By Kevin Raoofi
*/
#include <stdio.h>
#include <stdlib.h>
#define LINE_SEEK_AMOUNT (0x770)
#define TIME_OFFSET (61)
#define TIME_SIZE (10)
int main(int argc, char **argv)
{
if(argc < 2) {
fprintf(stderr, "You must enter exactly one argument to the file to read\n");
return 1;
}
char time[TIME_SIZE];
FILE *in;
in = fopen(argv[1], "r");
fseek(in, LINE_SEEK_AMOUNT + TIME_OFFSET, SEEK_SET);
int result = fread(&time, 1, TIME_SIZE, in);
fclose(in);
if (result != TIME_SIZE) {
fprintf(stderr,"Result size is %d instead of %d!\n", result, TIME_SIZE);
return 2;
}
puts(time);
return 0;
}
# This is a GNU Make file which describes how to build the application's
# DLL/SO for both x86 Windows and Linux systems.
#
#
# To do a full compile, invoke 'make all'
# To build just the test executable, invoke 'make bins'
#
CC:=$(shell which cc)
CFLAGS=-Wall -pedantic -O3 -std=c99
CFILES=./main.c
OUT_DIR=build
BIN_DIR=$(OUT_DIR)/bin
.PHONY: all bins clean fresh not_do assembly
VPATH =lib
all: bins
do: all
not_do:
$(error 'make do because not do is not an option')
bins:
@mkdir -p $(BIN_DIR)
$(CC) $(CFLAGS) $(LIBS) $(CFILES) -o $(BIN_DIR)/reader
$(OUT_DIR):
@mkdir -p $(OUT_DIR)
clean:
@rm -r $(OUT_DIR)
@rm -f *.o
%.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS)
%.s: %.c
$(CC) $(CFLAGS) $(LIBS) $(CFILES) -S $<
fresh: | clean all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment