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.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...
Back
Top