Author Topic: compiling problem  (Read 3087 times)

Drew::Blocks

  • Guest
compiling problem
« on: February 17, 2008, 10:23:03 pm »
i'm new to code::blocks and programming in general, so i'm gonna try and explain this as clearly as i can.

when i open code::blocks, the first thing you have to do is open a new project, o.k pretty easy so far.
so i then press console application, which i have been told to do, i click to do c not c++, beacuse that's what programming language i'll be using, i don't tick the thing underneath which says, "do not create any files", which makes the file main.c appear. well, i click open file-->main.c, which brings main.c up, when it's compiled and built, the program says hello world, fair enough. so i go back and open a different file, this is a tutorial file which worked 2 days ago, called sumsqares(by dodrill@swcp.com), it opens the file, when i say compile and build, it gives me lots of errors, now this isn't a problem, really, the problem is this: if i cut and paste this same code, into the main.c, it works. so then i work out, well i might need to add it to the workspace, so i add it to the workspace(the sumsquares.c file not main.c, which has already been added), and it doesn't work, but the main.c (with the source code from sumsquares) still works, code is this :
      /* Chapter 5 - Program 1 - SUMSQRES.C */
#include <stdio.h>

int sum; /* This is a global variable */

int main()
{
int index;

   header();          /* This calls the function named header */
   for (index = 1 ; index <= 7 ; index++)
      square(index);  /* This calls the square function */
   ending();          /* This calls the ending function */

   return 0;
}


header()        /* This is the function named header */
{
   sum = 0;     /* Initialize the variable "sum" */
   printf("This is the header for the square program\n\n");
}


square(number)   /* This is the square function */
int number;
{
int numsq;

   numsq = number * number;  /* This produces the square */
   sum += numsq;
   printf("The square of %d is %d\n", number, numsq);
}


ending()   /* This is the ending function */
{
   printf("\nThe sum of the squares is %d\n", sum);
}



/* Result of execution

This is the header for the square program

The square of 1 is 1
The square of 2 is 4
The square of 3 is 9
The square of 4 is 16
The square of 5 is 25
The square of 6 is 36
The square of 7 is 49

The sum of the squares is 140


now when i close both main.c and the sumsquares file and open a different file, and add into the workspace, it still compiles and builds main.c, even if i go as far as deleting the main.c file and restarting the computer it will still build main.c, with the source code from sumsquares(even though this file doesn't actually compile when i open it separetly.), i thought it might be due the file(s) options, in the create new project window and so redid it all, by pressing on c++, but that did the same thing

now another thing: when i refrain from opening either of them on the default workspace, it will compile both, but after a while it just stops allowing me to update it, so the compiler will basically not compile new code within in the files.

sorry if i'm being naive.

can you tell me what's going on, i didn't have a problem with it 2 days ago.

anyone who can help it would be much appreciated.

Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: compiling problem
« Reply #1 on: February 17, 2008, 10:59:21 pm »
My wild guess is that you're trying to compile two source files which include a main function, or you are not adding the file you need to the target you're compiling, or you are not correctly adding the file to the project.

Without the actual errors you are getting there's no easy way for us to know what you're doing wrong. I still think it's a problem with the way you set up your project file.