07-28-2010 04:14 AM
Hi,
1) it appears that your main is located within the callback function?
2) it would be easier assisting you if you could be more specific in telling 'what is not working': e.g.: are there errors; if yes, which error message do you receive...
07-28-2010 04:29 AM
should i move the main to the top?
error messgaes are as follows:
StimulsSignalTestV3.c - 20 errors, 1 warning
172, 29 Warning: Local 'x' has not been initialized. ---------------const int neg = x < 0.0;
204, 17 Undeclared identifier 'POINT'.-------------POINT* points = new POINT[no_of_points];
204, 24 Undeclared identifier 'points'..-------------POINT* points = new POINT[no_of_points];
204, 33 Undeclared identifier 'new'..-------------POINT* points = new POINT[no_of_points];
204, 37 Lvalue required..-------------POINT* points = new POINT[no_of_points];
204, 37 syntax error; found 'identifier' expecting ';'..-------------POINT* points = new POINT[no_of_points];
204, 56 Type error: pointer expected..-------------POINT* points = new POINT[no_of_points];
214, 17 syntax error; found 'identifier' expecting ';'.---------------a= GetCtrlVal ( panelHandle, PANEL_NUMERIC_1, &a )
216, 17 syntax error; found 'int' expecting ';'.------------- int w;
----------------------------------------------------------
07-28-2010 05:34 AM
This might be useful.
07-29-2010 07:05 AM
Nghtcrwlr,
Unfortunately, there are a number of differences in C++ with how it handles things very similar to C, like structs.
1) If you define a struct in the manner you did, i.e.
struct NAME { };
then you must declare any variables you want to be of that type as "struct NAME", rather than just "NAME"
if you really don't want to use the struct prefix, then define your struct as "typedef NAME_STRUCT { } NAME;"
2) The "new" and "new[]" operators do not exist in C. For memory allocation, look at the help for malloc, calloc, & realloc.
3) I'm not 100% sure, but I don't believe C supports 'const' parameters.
08-09-2010 07:01 AM
Hey all
I tried to change everything as you people mentioned. Now there comes only 2 errors. I dont understand them.
I defined the number of points as a constant in the beginning
#define no_of_points 130944
Then i have allocated the memory spaces by this :
struct POINT* points= calloc [no_of_points,1];
Then comes the two errors for this line.
Error 1: Unknown size of type '__cdecl pointer to void function(size_t,size_t)'.
Error 2: Operands of = have illegal types 'pointer to struct POINT' and 'pointer to pointer to void function(size_t,size_t)'.
Any ideas?
Thnx
08-09-2010 07:40 AM
calloc is a function, so you need to use (parentheses) rather than [brackets].
Also, if you want space for that many struct POINT structures, the second argument of calloc needs to be the size of a struct POINT, so:
struct POINT* points= calloc (no_of_points, sizeof(struct POINT));
08-09-2010 08:06 AM
Thank you msaxon. It worked. But i have another question. I have a function "square" in the program. There comes a linking error when compiling.
Undefined symbol '_square' referenced in "TestV3.c".
Y is this so? ¨
I have already included #include <math.h> in the header.
08-09-2010 08:56 AM
Hello everybdy. I need to hv a structutred program. now it seems to b too much lenghty and complicated.
I need to have the part in italics as a seperate function in seprate file and need to call it. For example in the place of the italics text i need something like this:
" GenerateFile();"
This should call the GenerateFile.c file in the project folder and run the progrm. I tried to do so but didnt work. Can any1 suggest alternative or better methods to do so? Below attached is my code:
Thanx.
#include <cvirte.h>
#include <userint.h>
#include "StimulsSignalTestV3.h"
#include <formatio.h>
#include <userint.h>
#include <cvirte.h>
#include <ansi_c.h>
#include <string.h>
#include "combobox.h"
static int panelHandle;
double p ,a;
#define no_of_points 130944
void InputComboValues (int panel, int control);
int CVICALLBACK PictureSelect (int panel, int control, int event,void *callbackData, int eventData1, int eventData2);
int main (int argc, char *argv[])
{
int panel;
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
if ((panel = LoadPanel (0, "StimulsSignalTestV3.uir", PANEL)) < 0)
return -1;
DisplayPanel (panel);
Combo_NewComboBox (panel, PANEL_STRING);
InputComboValues (panel, PANEL_STRING);
RunUserInterface ();
Combo_DiscardComboBox (panel, PANEL_STRING);
DiscardPanel (panel);
return 0;
}
void InputComboValues (int panel, int control)
{
Combo_InsertComboItem (panel, control, -1, "SQWAVE");
Combo_InsertComboItem (panel, control, -1, "SAWTOOTH");
}
int CVICALLBACK panel (int panel, int event, void *callbackData,int eventData1, int eventData2)
{
switch (event)
{
case EVENT_CLOSE:
QuitUserInterface (0);
break;
}
return 0;
}
int CVICALLBACK PictureSelect (int panel, int control, int event,void *callbackData, int eventData1, int eventData2)
{
char *value;
int vKey, length;
switch (event)
{
case EVENT_KEYPRESS:
vKey = eventData1 & VAL_VKEY_MASK;
if (vKey != VAL_ENTER_VKEY) /* fake an EVENT_COMMIT if Enter Pressed */
break;
case EVENT_COMMIT:
GetCtrlAttribute (panel, control, ATTR_STRING_TEXT_LENGTH, &length);
value = (char *)malloc(length+1);
GetCtrlVal (panel, control, value);
StringUpperCase (value);
if (strcmp (value, "SQWAVE") == 0)
DisplayImageFile (panel, PANEL_PICTURE, "SQWAVE.bmp");
else if (strcmp (value, "SAWTOOTH") == 0)
DisplayImageFile (panel, PANEL_PICTURE, "SAWTOOTH.bmp");
else
DeleteImage (panel, PANEL_PICTURE);
free(value);
break;
}
return 0;
}
int CVICALLBACK QuitCallback (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
QuitUserInterface (0);
break;
}
return 0;
}
int CVICALLBACK GenerateCallback (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
double square(double x);
{
double x;
// Period and amplitude.
double period = (p/2);
double amplitude = a ;
// Force positive argument.
const int neg = x < 0.0;
const double xx = neg ? -x : x;
// Scale the argument and compute the return value.
const double x_scaled = xx - floor(xx / period) * period;
const double ret_val = x_scaled < period / 2.0 ? amplitude : -amplitude;
// Antisymmetric square wave.
return !neg ? ret_val : -ret_val;
}
struct POINT
{
double x;
double y;
};
int main(int argc, char* argv[]) ;
{
unsigned int n;
double a, b = 0.0;
struct POINT* points= calloc (no_of_points, sizeof(struct POINT));
double *pt_p;
double *pt_a;
pt_a = &a;
GetCtrlVal ( panelHandle, PANEL_NUMERIC_2, pt_p ) ;
GetCtrlVal ( panelHandle, PANEL_NUMERIC_1, pt_a ) ;
int w;
double g= 512;
//Create a file to write to
FILE *OutFile = fopen("Extern_stimulussignal.sig","w");
for(w=0;w<10;w++)
{
const double increment = 1.0;
points[0].x = 0;
points[0].y = square(points[0].x);
for(n = 1; n <= (128*g)/pow((double)2, w); n++)
{
points[n].x = points[n-1].x+ increment;
points[n].y = square(points[n].x);
//printf("%12.7f\t%12.7f\n", points[n].x, points[n].y);
//Send data to file
fprintf(OutFile,"%12.7f\n", points[n].y) ;
//("%12.7f\t%12.7f\n", points[n].x, points[n].y);
}
}
//Close the file
fclose(OutFile);
break;
}
return 0;
}
}
08-10-2010 07:13 AM
Hi all.
I modified the prgm by givinbg it a structure as shown in the attachment. Can anyone analyze it an say whether am in the right path. When i did like this i got an error messgae
" Redeclaration of 'square' previously declared at square.h:1."
thanks for any ideas!
"
08-10-2010 07:48 AM
according to your hard to read attachment you have different declarations of your function - in the include file it has one argument, in your C snippet it appears to have two.