Welcome to Soft32 Linux Forums!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

need help on simple c program compiled by gcc

 
   Soft32 Home -> Linux -> General Discussions RSS
Next:  [PATCH] msi-x: let drivers retry when not enough ..  
Author Message
fsshl

External


Since: May 07, 2009
Posts: 1



(Msg. 1) Posted: Thu May 07, 2009 12:57 am
Post subject: need help on simple c program compiled by gcc
Archived from groups: linux>redhat (more info?)

hi redhat linux users:


I am using MAC osx 's gcc to compile a simple program

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)

please help why it did not work by that way
eric
Back to top
Login to vote
Teo

External


Since: May 02, 2007
Posts: 8



(Msg. 2) Posted: Thu May 07, 2009 2:08 am
Post subject: Re: need help on simple c program compiled by gcc [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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
Back to top
Login to vote
Michael

External


Since: May 07, 2009
Posts: 1



(Msg. 3) Posted: Thu May 07, 2009 9:56 am
Post subject: Re: need help on simple c program compiled by gcc [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Thu, 7 May 2009 02:08:04 -0700 (PDT)
Teo <matteo.corti.DeleteThis@gmail.com> wrote:
> >   #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;}

> Please ask to a C group but I think that you should get some more
> programming/C knowledge before starting to code

This is almost certainly a homework problem.
--
Michael
Back to top
Login to vote
Display posts from previous:   
Related Topics:
someone has compiled apache 2.x with mpm worker over rh3.0? - some days ago i wrote a post about some problems i've find compiling and working with apache 2 with mpm worker over a....

FC3 self-compiled kernel - lost mouse?! - Folks, I've got a *weird* problem. Got/installed stock FC3-2.6.11-1.14smp kernel, it works fine. Changed a few..

program - I have some World of warcraft movies and i like the music on them. I would like to know of a program that will take ou...

Trying to compile a program - I have some source code I would like to compile & run under linux. It is mostly in c and fortran. I believe this....

"df" from C program - I need to get the state of my disk from a C program, in particular, how much disk is used and how much is left. How do...

file/program permission - Hi guys. When I launch a particular C compiler(icc) as root, it runs fine. However, when I try to run it as a normal....
       Soft32 Home -> Linux -> General Discussions All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Categories:
 Windows
  Linux
 Mac
 PDA


[ Contact us | Terms of Service/Privacy Policy ]