LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

several C-Files

Hy,


I like to write a program in LabWindows.

I’ve got two c-files. One with the main-function and the other with a subroutine.

When the user set the #define to 1 the program should work with the subroutine.

 


But it doesn’t.

I already read other posts concerning this subject but it didn’t help me.

 


Thanks for helping me.


 

The program doesn’t print: "The function ‘temperatur’ has been executed"

Here my program.


------------------------------
/* temp.h */

#include <ansi_c.h> 

 

void temperature(); 

--------------------------------


/* main.h */

#include <ansi_c.h>


#include <utility.h>

#define TEMP 1 // the user set 1 or 0

--------------------------------


/* temp.c */

#include "temp.h"

void temperature()


{


     printf("The function ‘temperatur’ has been executed");


}

--------------------------------


/* main.c */

 


#include "main.h"


#include "temp.h"



void main()


{


      if(TEMP)


    {

                 
        void temperature();


        printf(“TEMP=1”);


    }


    else


    {


        printf(“TEMP=0”);


    }


}

 

 

0 Kudos
Message 1 of 6
(3,653 Views)

Hy,

i'm not sure how c ansi reacts to if(1) or if (0), so how about

     if(TEMP == 1)
    {                 
        void temperature();
        printf(“TEMP=1”);
    }
    else
    {
        printf(“TEMP=0”);
    }

?

Greetings

Norbert

0 Kudos
Message 2 of 6
(3,641 Views)
You have a 'void' too many. The one in red is confusing the compiler into thinking you are declaring another function prototype, rather than calling the previously defined function. Just delete it and it should work.

void main()
{
      if(TEMP)
    {                 
        void temperature();
        printf(“TEMP=1”);
    }
    else
    {
        printf(“TEMP=0”);
    }
}

JR

0 Kudos
Message 3 of 6
(3,638 Views)
Hy,

thank you for your answers.

I tried a version with 'if (TEMP == 1)' but it works the same way as before.
When I delete the 'void' before temperature in the main-function, the program returns an error: "missing prototype".

By including the temp.c instead of the temp.h I get the message: "Project link error: Multiply defined symbol '_temperature' in modules 'main.c' and 'temp.c'"

Any other ideas?

Thanks.
0 Kudos
Message 4 of 6
(3,632 Views)

In both your temp.h and temp.c files, instead of void temperature() you could try void temperature(void) instead. I assume all these files are within your CVI project?

BTW, you should never #include a .c source file inside another one. Leads to all sorts of problems.

JR

0 Kudos
Message 5 of 6
(3,628 Views)
Hy,

thanks for your help.

Now it works.

Here the code for all others who have trouble including several c-files
-----------------------
/* main.h */

#include <ansi_c.h>
#include <utility.h>

#define TEMP 1 // the user set 1 or 0

-----------------------
/* temp.h */

#include <ansi_c.h>

void
temperature(void); 



-----------------------
/* temp.c */

#include "temp.h"

void temperature ()
{
 printf("The function 'temperature' has been executed");
}

-----------------------
/* main.c */

#include "main.h"


#include "temp.h"

void main()


{


    if(TEMP)


    {


        temperature();


        printf("TEMP=1\n");


    }


    else


    {


        printf("TEMP=0\n");


    }


    Delay(10.0);


}



0 Kudos
Message 6 of 6
(3,609 Views)