How can I fix syntax errors in my C code?

Click For Summary

Discussion Overview

The discussion revolves around fixing syntax errors in C code, specifically within the context of programming in S-Function Simulink. Participants seek assistance in debugging and clarifying issues related to their code.

Discussion Character

  • Technical explanation
  • Homework-related
  • Debate/contested

Main Points Raised

  • One participant expresses a need for help with debugging syntax errors in their C code.
  • Another participant requests the code, errors, and the goal of the program to provide assistance.
  • A participant shares their code and lists specific syntax errors encountered, including "syntax error; found `if' expecting `;'" and "unrecognized statement."
  • A subsequent reply identifies that the errors are due to extra semicolons after the `if` statements and suggests their removal.
  • Another participant reiterates the need to remove the semicolons after the `if` statements to resolve the syntax errors.

Areas of Agreement / Disagreement

There is a general agreement on the identification of extra semicolons as the source of the syntax errors, but the discussion does not reach a consensus on other potential issues or further debugging steps.

Contextual Notes

The discussion does not address any missing assumptions or unresolved mathematical steps related to the code provided.

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.
 

Similar threads

Replies
86
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 25 ·
Replies
25
Views
1K
  • · Replies 15 ·
Replies
15
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 16 ·
Replies
16
Views
5K
  • · Replies 133 ·
5
Replies
133
Views
13K
  • · Replies 22 ·
Replies
22
Views
3K
  • · Replies 397 ·
14
Replies
397
Views
22K
  • · Replies 9 ·
Replies
9
Views
2K