Skip to content

Instantly share code, notes, and snippets.

@JamieChung
Created September 13, 2011 15:18
Show Gist options
  • Save JamieChung/1214082 to your computer and use it in GitHub Desktop.
Save JamieChung/1214082 to your computer and use it in GitHub Desktop.
#include <stdio.h>
## To detect the arguments from the command line
int main ( int argc, char *argv[] )
## Argument Count
## Array of Argument Values
// First argument is assumed to be the name of the program (problem2)
// Second argument would be the input file
if ( argc != 2 )
{
printf("Invalid number of commands");
return 0;
}
// Open the file for reading ("r")
FILE *file = fopen(argv[1], "r");
if ( file == 0 )
{
printf("Error reading file.\n");
return 0;
}
// Array of two because first index is the letter, second index is null terminator \0
char string[2];
//
int digit1 (CPI);
int digit2 (number of instructions)
while ( fgets ( line_buffer, sizeof line_buffer, file ) != NULL )
{
// read the values from the line buffer of each line... (%STRING %DIGIT %DIGIT) =>
sscanf(line_buffer, "%s %d %d", string, &digit, &digit);
}
// This is how you get the input from the file... have fun.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment