Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added first solution

  • Loading branch information...
commit cd4fc4cbfea8fae0708a0fd8221c97a25601db68 1 parent 554c8a7
Rob Righter authored
BIN  01-recurse_expand_and_print_file/a.out
View
Binary file not shown
7 01-recurse_expand_and_print_file/infile.txt
View
@@ -0,0 +1,7 @@
+This is my SSH config
+@/Users/rob/.ssh/config
+
+This is another file that has a nested file
+@./nested.txt
+
+And Now we are all done
34 01-recurse_expand_and_print_file/main.c
View
@@ -0,0 +1,34 @@
+#include <stdio.h>
+#include <string.h>
+
+const int MAX_CHARS_PER_LINE = 300;
+
+void recurseFile(const char *infile){
+ //fprintf(stdout, "About to open file '%s'\n", infile);
+ FILE *f = fopen(infile, "r");
+ if(!f){
+ fprintf(stderr,"COULD NOT OPEN THE FILE");
+ }
+ char line[MAX_CHARS_PER_LINE];
+ int count = 0;
+ while(fgets(line, MAX_CHARS_PER_LINE, f)){
+ //fprintf(stdout, "Line %d: %d Characters\n", count++, (int)strlen(line));
+ line[(int)strlen(line)-1] = '\0';
+ if( ((int)strlen(line)) > 1 && line[0] == '@'){
+ recurseFile( (const char*)(line+1) );
+ }
+ else{
+ fprintf(stdout, "> %s \n", line);
+ }
+ }
+ fclose(f);
+}
+
+int main(int argc, char *argv[]){
+ if(argc < 2){
+ fprintf(stdout,"Usage: recurse-file [filename]\n");
+ return 1;
+ }
+ recurseFile(argv[1]);
+ return 0;
+}
5 01-recurse_expand_and_print_file/nested.txt
View
@@ -0,0 +1,5 @@
+Inside nested txt.
+Lets nest another one
+@./nested2.txt
+
+done with nested 1
4 01-recurse_expand_and_print_file/nested2.txt
View
@@ -0,0 +1,4 @@
+And these
+are some
+lines inside
+nested 2
Please sign in to comment.
Something went wrong with that request. Please try again.