Code::Blocks Forums
User forums => Using Code::Blocks => Topic started by: Xian82 on November 12, 2009, 11:10:07 pm
-
Hi there,
Two things:
1)I'm new to this forum so hi all.
2)I have an issue with <complex.h>, I cannot declare variables using this library. I'm coding in C and using Code::Blocks and I've literally copied and pasted sample code from online and found that it will not compile for me. How does one declare a variable using <complex.h>? Is this a common issue with Code::Blocks? Here's some sample code that doesn't work for me:
#include <complex.h>
#include <stdio.h>
int main(void)
{
complex c=2+3*I;
printf("%g + %gi\n", creal(c), cimag(c));
return 0;
}
However this compiles but when I try to assign a value to the variable it no longer works:
#include <complex.h>
#include <stdio.h>
int main(void)
{
_complex c;
return 0;
}
Can anyone help me out with this?
-
Code::Blocks is an IDE; it is NOT a compiler!!
The website does not support learning how to program in C/C++ or any other language.
Tim S.
-
Even if the forum is about an IDE, I woud try to guess what is wrong :) First of all, you cannot compile such things in C, you need a C++ compiler, therefore, a C++ project.
(1) The first program will not compile in C. That's because you need classes and custom defined operators '+' and '*' for it. Nothing like that is supported in C. The statement "complex c = 2 + 3*I;" is an error in C.
(2) The second program can compile in C, providing you have defined a structure "_complex". Usage of that structure is the same as usage of any other structure:
c.re = 2;
c.im = 3;
but this is not the thing you have wanted most likely. Therefore, switch to C++ and make sure you are writing a C++ project.