for this program I'm writing I need to take input from a file and draw a fractal image based on the Lindenmayer System. The input looks a little bit like this:
Code:4 25 20.0 -90.0 aF 24 a -> FFFFFy[++++n][----t]fb b -> +FFFFFy[++++n][----t]fc c -> FFFFFy[++++n][----t]fd d -> -FFFFFy[++++n][----t]fe e -> FFFFFy[++++n][----t]fg g -> FFFFFy[+++fa]fh h -> FFFFFy[++++n][----t]fi i -> +FFFFFy[++++n][----t]fj j -> FFFFFy[++++n][----t]fk k -> -FFFFFy[++++n][----t]fl l -> FFFFFy[++++n][----t]fm m -> FFFFFy[---fa]fa n -> ofFFF o -> fFFFp p -> fFFF[-s]q q -> fFFF[-s]r r -> fFFF[-s] s -> fFfF t -> ufFFF u -> fFFFv v -> fFFF[+s]w w -> fFFF[+s]x x -> fFFF[+s] y -> Fy
I am trying to get the values using scanf :
currently I'm trying to grab "aF" by initializing "axom" as a string (I included <string.h> in the header) and assigning the 5th value in the file to it. However I know that there can be issues using a string in scanf.Code:int edf, depth, numRules, numImages; double angle, initHead; char *lhs, *rhs, *axiom; //lhs and rhs are for storing the rules and not used here scanf("%d %d %lf %lf %c", &numImages, &edf, &angle, &initHead, &axiom);
I've tried alternatively tried making axiom an array of chars but that just grabs everything else in the file until the array is filled and the length of "axiom" will vary by test file.
The only other way I can currently think of involves storing the whole file to an array of chars and iterating through one by one. Is there an easier way to do this or am I just over-thinking things?