I'm writing a function that takes a file, reads the file into a buffer while keeping count of the lines, then takes each line and plugs the content into a simple structure. I did it that way because the number of lines is variable and will determine, obviously, the number of structs needed. So I get the number of lines (nofl) and in the middle of the function do this:

struct thestruct new[nofl];

I was getting a segfault, so to make sure nofl was correct, i inserted the following line RIGHT BEFORE the last one:

printf("--%d--\n", nofl);

AND NOW NO SEGFAULT!!! Nothing else is changed, but adding and subtracting that one line makes all the difference. Really, really, really. More observations:
1) Up until now I've been declaring variables (inc. structs) at the beginning of a function, but I've never heard tell that it must be so. Does this have anything to do with it?
2) The segfault actually occurs later when new[1] (ie. the 2nd struct in the array) is called on (it turns out not to exist).
3) "nofl" is determined on the line immediately preceeding the printf statement.
4) if I put the printf statement after the struct declaration, the segfault returns.