I wrote this program to build a number diamond. The issue is that when I compile the program, it throws the error
build2.c:(.text+0x5): undefined refe
The function print_pattern is not terminated at proper place but instead at the very end of the file:
void print_pattern(int size){
...
... end of the loop
}
... more functions
...
... end of print_pattern
}
This results into defining nested functions instead of global level.
It's generally good habit to indent the blocks, in which case you would realized the mistake very quickly.
You seem to have nested functions; this is (a) a non-standard GCC extension, and (b) I presume the scope of the nested get_input()
function is the enclosing function, not the file scope. The solution is to move get_input()
to file scope. At the end of print_pattern()
add an extra }
, and delete the final }
at the end of the file.
Also, please format your code - most IDEs these days have options to tidy it up, and with correct indentation you may have seen your problem earlier.
Oh, and as a bonus bug fix, you also have in get_input()
:
while (cont = 1)
This will always be true - use this instead:
while (cont == 1)