Hi friends,
I am using GNU GCC Compiler
OS: win7 32bit
/* Program 4.2 Drawing a box */
#include <stdio.h>
int main(void)
{
printf("\n**************"); /* Draw the top of the box */
for(int count = 1 ; count <= 8 ; ++count)
printf("\n* *"); /* Draw the sides of the box */
printf("\n**************\n"); /* Draw the bottom of the box */
return 0;
}
when i try to compile the code i got fallowing error.
C\48.c|6|error: 'for' loop initial declarations are only allowed in C99 mode|
C\48.c|6|note: use option -std=c99 or -std=gnu99 to compile your code|
If anybody know how to change it to c99mode please help me.
Thanks & Regards,
Deva
Hi, I changed to -std=c99 mode is this way correct ?
Please see picture
Untitled.png:(http://imageupload.org/thumb/thumb_132616.png) (http://imageupload.org/?d=FEFA34451)
Hi friends,
My problem solved. many of them adviced me to change settings to -std=c99 But its not worked because my compiler is GNU GCC Compiler.
Here is see how the problem is fixed.
In the Compiler and Debugger settings. Compiler settings tab - Other Options. I added there -std=gnu99
So Problem solved.
Friends thanks very much for your advices & time.
Thanks & Regards,
Deva
Go to the Project menu, then Build Options..., then Compiler Settings|Other options tab, then enter -std=c99 and hit OK.
Hi,
Thanks for your reply. In the projecet menu build options is disable I mean its not highlited. How can we enable it?.
CB is project based. Before you write any code, create a project from Create New Project on the CB startup screen, and select Console Application - the Build Options will be enabled after you create a project.
Quote from: Neil Butterworth on November 10, 2011, 09:31:30 AM
CB is project based. Before you write any code, create a project from Create New Project on the CB startup screen, and select Console Application - the Build Options will be enabled after you create a project.
Wrong, C::B supports single file compilation, too.
For the compilation it uses the default compiler,
so you can set the option in the settings,
but this is not a good practice in the long run.
No, debugging is supported in single file mode.
> Wrong, C::B supports single file compilation, too.
What is "wrong"? Do you deny that that CB is project based? Can you use Build Options without a project, which is what the OP needs to do, without using what you yourself say is "bad practice"? No, you can't.
I gues you use a *.c file.
The easiest way would be to rename it to *.cpp, so it is compiled with the c++-compiler.
> The easiest way would be to rename it to *.cpp, so it is compiled with the c++-compiler.
But then he runs into problems if he uses C99 features not supported by C++.
IMO, Jens is correct. You problem consists in "for( int count = 1 ; ..." This kind of declaring local variables in a loop statement (or other statements) is usual in C++ for a long time. Perhaps, a norm is it starting from C99. GCC is over strict sometimes ...
(1) Either switch to C++ by renaming 48.c to 48.cpp or selecting C++ compiler explicitely.
(2) Or declare "int count" like a normal variable declaration at the beginning of main().
When you opt for (1) you can get a similar paranoid message. When you opt for (2), you should pass even with a C compiler.
@Radek. It is perfectly legal (and good) C99 code, and the OP obviously wants to use C99. Telling him to switch to C++, a completely different language, is IMHO very bad advice.
Hi friends,
Non of the your advices working. Is there any way still fix the problem. Actually I am newbie to programming. I am just teaching my self from book "C-FromNoviceToProfessional4thEd(2006)" by Ivor Horton, Apress.
I tried to compile the same code in Borland Turboo C++ compiler. Its work fine.
But i really like to use CB because its highlight the syntax in colors. So, code looks clean & good.
Any help greately appreciated.
Thanks & Regards,
Deva
@Deva The code will definitely compile if you rename the file to a .cpp extension, but if you are trying to learn C rather than C++ this is not the best solution, as it means things that are mistakes in C but not in C++ will not be caught. My solution of creating a console application project and supplying the -std=c99 option should definitely work - it did when I tried it myself - and is the correct way to go if you want to learn C99. Did you actually try it?
The following does not work?
#include <stdio.h>
int main(void)
{
int count;
printf("\n**************");
for( count = 1 ; count <= 8 ; ++count ) printf("\n* *");
printf("\n**************\n");
return 0;
}