How can I fix syntax errors in my C code?

In summary: Your code should look like this:In summary, the conversation was about someone needing help with their C code. They posted their code and errors in the hopes that someone would be able to assist them. However, someone pointed out that there were some extra semicolons causing syntax errors in the code. They were advised to remove these and then repost their code for further help.
  • #1
mbolhi
10
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
  • #2
Lots of people program in C, including quite a few here at Physics Forum. What difficulties are you having?
 
  • #3
well, i am quite novice and i have some error i need to debug in C code

can you help me please?

thanks
 
  • #4
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.
 
  • #5
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
 
  • #6
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.
 

1. What is the C programming language?

The C programming language is a general-purpose programming language that was created in 1972 by Dennis Ritchie. It is a high-level language that is used for developing operating systems, applications, and other software. C is known for its efficiency, portability, and speed.

2. What are the benefits of learning C?

Learning C can provide a strong foundation for understanding other programming languages due to its low-level nature. It also allows for efficient memory management and has a large library of functions that can be used for various purposes. Additionally, many software applications and operating systems are written in C, making it a valuable skill for programmers.

3. What are the basic data types in C?

The basic data types in C are integer, character, float, and double. Integers are used to represent whole numbers, characters are used to represent individual characters, and floats and doubles are used to represent decimals. There are also derived data types in C, such as arrays, structures, and pointers, which are made up of the basic data types.

4. How do you write a simple program in C?

To write a simple program in C, you will need to have a text editor and a C compiler. The program should start with the #include <stdio.h> statement, followed by the int main() function, which is where the program execution begins. You can then write your code within curly braces {} and use semicolons ; to end each line of code. Once you have written your program, you can compile it using the C compiler and then run it to see the output.

5. How can I improve my skills in C programming?

To improve your skills in C programming, it is important to practice regularly and work on different projects. You can also read books and online resources to learn new techniques and best practices. Collaborating with other programmers and participating in online communities can also help you learn from others and improve your skills. Additionally, setting small, achievable goals for yourself can help you track your progress and continuously improve.

Similar threads

  • Programming and Computer Science
Replies
15
Views
1K
  • Programming and Computer Science
Replies
8
Views
867
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
4
Replies
107
Views
5K
  • Programming and Computer Science
Replies
22
Views
2K
  • Programming and Computer Science
12
Replies
397
Views
13K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
9
Views
1K
  • Programming and Computer Science
Replies
11
Views
1K
  • Programming and Computer Science
Replies
1
Views
235
Back
Top