#include #include int main( int argc, char *argv[] ){ if( argc == 2 ) { unsigned int horizontal = 0; unsigned int depth = 0; FILE *fp=fopen(argv[1], "r"); while (!feof (fp)){ char direction[7] = ""; int amount = 0; fscanf(fp, "%s %d\n", direction, &amount); if ( strcmp(direction,"forward") == 0 ) horizontal+=amount; else if ( strcmp(direction,"down") == 0 ) depth+=amount; else if ( strcmp(direction,"up") == 0 ) depth-=amount; else printf("Hopefully we don't get here\n"); } printf("Horizontal: %d\n", horizontal); printf("Depth: %d\n", depth); printf("Product: %d\n", horizontal * depth); fclose(fp); return 0; } else { printf("You need to provide a file\n"); return 1; } }