Commits

Tony Cesaro committed bcb195a

added command line parsing

  • Participants
  • Parent commits c5b9833

Comments (0)

Files changed (1)

 
 #define CHUNK 1024
 
-int main (int argc, char **argv)
+int main (int argc, char *argv[])
 {	
+	if (argc > 3)
+	{
+		fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
+		return 1;
+	} 
+
+	char* filename = NULL;
+	char* pattern = NULL;
+
+	while (--argc > 0)
+	{
+		filename = argv[1];
+		pattern = argv[2];
+	}
+
+	printf ("File being concatenated: %s\n", filename);
+	printf ("Pattern used for filter: %s\n\n", pattern);
+
 	char buffer[CHUNK];
 	FILE *ifp;
 	size_t nread;
-
-	ifp = fopen("test.txt", "r");
+	
+	ifp = fopen(filename, "r");
 
 	if (ifp == NULL)
 	{