Pregunta

I'm an absolute beginner to C and I've read a few books but never really played with it. I'm starting to try to apply what I've read with a very simple program that returns the sin of a number. The hardest thing I've encountered with C is knowing how and when to use pointers.

I'm sure this is simple but here is how I've written my test:

#include <stdio.h>
#include <math.h>

int main(void)
{
   double x;

   printf("Enter a number to calculate the sin(x): \n");
   scanf("%lf", &x);

   printf("sin(%lf) = %lf\n", x, sin(x));

   return 0;
}

I'm compiling and executing this code in Ubuntu

gcc -lm sinCalc.c && ./a.out 

Error I'm receiving is this:

/tmp/blaha.o: In function `main':
sinCalc.c:(.text+0x31): undefined reference to `sin'
collect2: ld returned 1 exit status
¿Fue útil?

Solución

Undefined symbols are resolved left to right, so

gcc sinCalc.c -lm && ./a.out

should work.

Are they [structs] like an interface in Java?

No. Structs are an aggregate of a number (1 or more) of types that can be dealt with as a single unit in certain circumstances (assignment, parameter passing).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top