Message from C, C++ discussions

December 2019

— Yes


It's not homework I'm doing, I'm just trying to simplify my life when doing my homework (we are working on matrices and printing out a matrix comes out multiple times)

— The issue is I've created the function that does that

— But it only works within the same file of the main program

— So your problem rather is: how to call a function from a different file in C

— If it's in a separate file I cannot find a way to make it work because I guess it gets interpreted as trying to make a variable size matrix (which I know I cannot create without pointers)

Message permanent page

— Well, yes, but actually no, rather how to make the same function in a different file that is, in a way, a library of functions that more or less do the same thing

Message permanent page

— You will, indeed, run into that very problem, which I advise to solve using the very solution you know is tiresome. Sadly, C is more of a syntactic sugar on top of assembly code than a proper programming language

Message permanent page

— So do I just open the file, copy paste the function in the main program and call it a day? that's how I've been dealing with it

Message permanent page

— In C, you need to write both a header file (contains the definitions of the functions and types) and an implementation file. The header generally have a .h extension and the implementation a .c extension

Message permanent page

— Mmm when I get home I'll read about this more, our teacher didn't get there yet and I'm new to C

— The declaration of a function in C89 is at least the return type of the function followed by its name and parentheses. In C99, the type of the parameters is also required, separated by commas, within the parentheses

Message permanent page