Tuesday, July 14, 2009

C problem, function & pointer declaration error?

Hi,


When i run this code, I get the following error. When i remove the function declarations it compiles. But function+pointer declarations give the error!


Urgent project deadline - please help!!


Error 1 error C2143: syntax error : missing ';' before 'type' c:\nofrduk\Microscribe2\MicroRun7...








void main(){


FILE *posrot;


char letter;


float DeltaLonger=0.25f; // Diff. by which special stylus tip is longer than original one


double A; // declare stylus rotation angle


arm_rec arm; // declare "struct arm_rec"


arm_init(%26amp;arm); // initialize "struct arm_rec" for further use


arm_length_units(%26amp;arm,MM); // want millimeters


arm_angle_units(%26amp;arm, DEGREES); // want degrees





double ** p1 = (double **)malloc(sizeof(double)*ROW*COL);


double ** p1_t = (double **)malloc(sizeof(double)*ROW2*COL2);

C problem, function %26amp; pointer declaration error?
Are you trying to call the functions or declare them in main()? If you're declaring them they need a return type. If you're calling them then they need declaring outside the scope of main() and also defining. The code snippet you've given also doesn't include any definition or declaration of the structs you're using - you'll need these as well.





Also main should always return an int.
Reply:things would be so much easier if you could post the error message, and not just truncate it.





you have a lot of problems in the code.





// is not a valid comment for C, only for C++. But you say you have a C problem.





you didn't include header files.





your declaration of p1 and p2 is AFTER executable code - that's not allowed in C, only in C++. You have to move the declaration of p1 and p2 to the top of the function, below "arm_rec arm;" or "double A;" .





etc. etc.


No comments:

Post a Comment