Dear Eric,
On May 7, 9:57 am, fs....TakeThisOut@yahoo.com wrote:
> hi redhat linux users:
>
> I am using MAC osx 's gcc to compile a simple program
and why if you are using OS X are asking a RedHat group?
In fact this has nothing to do with the system: it's a C problem
should go to a C group.
> but it can not run(not run as I intended)
>
> #include <stdio.h>
> #include <math.h>
> int main() {
> double x1, y1;
> printf("please enter floating number\n\n");
> scanf(y1);
> x1 = sin(y1);
> printf("x1 = ", x1, " \n");
> return 0;}
>
> ---------------------------------------------------------------------
> $ ./a.out
> please enter floating number
>
> x1 =
> -------------------------------------
> I just like to read a double y1, then printout x1 which equal sin(y1)
This is not what happens with the code you supplied:
../test.c: In function ‘main’:
../test.c:7: error: incompatible type for argument 1 of ‘scanf’
if you then read the manual page for scanf (man scanf) you see:
int scanf(const char *format, ...);
You have to supply the format:
scanf("%lf", &y1);
Note that you have to specify a pointer (a memory location where scanf
will write the result).
Your printf line is also wrong:
int printf(const char *format, ...);
Then:
printf("x1 = %f\n", x1);
You specify a format string (just one with placeholders) and then the
list of substitution variables.
> please help why it did not work by that way
> eric
Please ask to a C group but I think that you should get some more
programming/C knowledge before starting to code
In any case run the compiler with -Wall: it will generate warnings
Matteo