How can I fix syntax errors in my C code?

AI Thread Summary
The discussion centers on a user seeking help with debugging C code in S-Function Simulink. The user is a novice and has encountered syntax errors related to the use of semicolons after if statements. The key issue identified is the presence of unnecessary semicolons that terminate the if statements prematurely, leading to syntax errors. The solution provided emphasizes removing these semicolons to resolve the errors and allow the code to function correctly. The conversation highlights the importance of sharing specific code and error messages for effective assistance in programming.
mbolhi
Messages
10
Reaction score
0
Hi all,

I am learning C language in S-Function Simulink

does anyone prgram in C?

I need help please

Thanks
 
Technology news on Phys.org
Lots of people program in C, including quite a few here at Physics Forum. What difficulties are you having?
 
well, i am quite novice and i have some error i need to debug in C code

can you help me please?

thanks
 
Well you are going to need to post your code, your errors, and the goal of the program or no one will be able to help you.
 
here is my code and thanks for your help in advance!

double theta, A1, A2, phi, C, A0, L ;

theta = 1;

A0 = 0.7;
L = 0.160;

C = sqrt(A0*A0 + L*L);

phi = atan(A0/L);


//**************************************************************************




if (C*C + L*L - 2*L*C*cos(phi - theta)>0.0);
{
A1 = sqrt(C*C + L*L - 2*L*C*cos(phi - theta));
}

else if (C*C + L*L - 2*L*C*cos(phi - theta)<0.0);
{

printf("error -- sqrt_negative\n");

}

if (C*C + L*L - 2*L*C*cos(phi + theta)>0.0);
{
A2 = sqrt(C*C + L*L - 2*L*C*cos(phi + theta));
}

else if (C*C + L*L - 2*L*C*cos(phi + theta)<0.0);
{
printf("error -- sqrt_negative\n");
}



I get these errors:

syntax error; found `if' expecting `;'

unrecognized statement
 
mbolhi said:
here is my code and thanks for your help in advance!

double theta, A1, A2, phi, C, A0, L ;

theta = 1;

A0 = 0.7;
L = 0.160;

C = sqrt(A0*A0 + L*L);

phi = atan(A0/L);


//**************************************************************************




if (C*C + L*L - 2*L*C*cos(phi - theta)>0.0);<---- Remove semicolon
{
A1 = sqrt(C*C + L*L - 2*L*C*cos(phi - theta));
}

else if (C*C + L*L - 2*L*C*cos(phi - theta)<0.0);<---- Remove semicolon
{

printf("error -- sqrt_negative\n");

}

if (C*C + L*L - 2*L*C*cos(phi + theta)>0.0);<--- Remove semicolon
{
A2 = sqrt(C*C + L*L - 2*L*C*cos(phi + theta));
}

else if (C*C + L*L - 2*L*C*cos(phi + theta)<0.0);<--- Remove semicolon

{
printf("error -- sqrt_negative\n");
}



I get these errors:

syntax error; found `if' expecting `;'

unrecognized statement

You have some extra semicolons that need to be removed.
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
Back
Top