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 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Back
Top