Changed the variable name 'index' to 'pos' due to compilation error when not using the -std=c99 flag with gcc.