473,385 Members | 1,564 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

function problem

I know this must have some simple answer but I'm having trouble with this
function I wrote.
stdio.h
math.h

double relstr (double x,double y)
{double n;
n=x/y;
printf("%f",(return n;));}
I dunno.

Bill

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Nov 14 '05 #1
9 1544
Bill Cunningham wrote:
I know this must have some simple answer but I'm having trouble with this
function I wrote.
stdio.h
math.h

double relstr (double x,double y)
{double n;
n=x/y;
printf("%f",(return n;));}
I dunno.


Bill...

I hope your C compiler is having trouble with this one, too.
You're trying to code a statement where the only allowable
construct is an expression.

--
Morris Dovey
West Des Moines, Iowa USA
C links at http://www.iedu.com/c
Read my lips: The apple doesn't fall far from the tree.

Nov 14 '05 #2
On Thu, 15 Jan 2004 21:14:28 -0500, "Bill Cunningham"
<no****@nspam.net> wrote in comp.lang.c:
I know this must have some simple answer but I'm having trouble with this
function I wrote.
stdio.h
math.h

double relstr (double x,double y)
{double n;
n=x/y;
printf("%f",(return n;));}
I dunno.

Bill


One of your problems is that you are using a broken compiler, if it
compiles this, since the code is illegal. You can't use a return
statement as an argument to a function, as it does not yield a value.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #3
One of your problems is that you are using a broken compiler, if it
compiles this, since the code is illegal. You can't use a return
statement as an argument to a function, as it does not yield a value.

Oh no the compiler won't compile this. It says error before return. Don't I
have to get the code to return the value of n and send it to stdout via
printf?

Bill

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Nov 14 '05 #4
Bill Cunningham wrote:
One of your problems is that you are using a broken compiler, if it
compiles this, since the code is illegal. You can't use a return
statement as an argument to a function,
as it does not yield a value.

Oh no the compiler won't compile this. It says error before return.
Don't I have to get the code to return the value of n and
send it to stdout via printf?


#include <stdio.h>

double relstr (double x, double y)
{
double n;

n = x / y;
printf("%f", n);
return n;
}

--
pete
Nov 14 '05 #5
On Thu, 15 Jan 2004 22:15:32 -0500, in comp.lang.c , "Bill Cunningham"
<no****@nspam.net> wrote:
One of your problems is that you are using a broken compiler, if it
compiles this, since the code is illegal. You can't use a return
statement as an argument to a function, as it does not yield a value.
Oh no the compiler won't compile this


thats a relief.
. It says error before return. Don't I
have to get the code to return the value of n and send it to stdout via
printf?


read what Jack said again.,
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 14 '05 #6
On Thu, 15 Jan 2004 21:14:28 -0500, in comp.lang.c , "Bill Cunningham"
<no****@nspam.net> wrote:
I know this must have some simple answer but I'm having trouble with this
function I wrote. stdio.h
math.h
first off, get a better newsreader - one that doesn't strip out the
#include and <>'s from your posts !!
double relstr (double x,double y)
{double n;
n=x/y;
printf("%f",(return n;));}


Two problems here:
1) you can't use a return statement as an argument of a function.
2) your brace style is EXCEPTIONALLY horrible. Do NOT follow or
precede braces with code, it makes it unbelievable hard to read.

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 14 '05 #7
> double relstr (double x, double y)
{
double n;

n = x / y;
printf("%f", n);


ITYM:
printf("%lf", n);
Nov 14 '05 #8
Old Wolf wrote:
double relstr (double x, double y)
{
double n;

n = x / y;
printf("%f", n);


ITYM:
printf("%lf", n);


No.

--
pete
Nov 14 '05 #9
>> printf("%f", n);
[where n is a "double"]

In article <news:84**************************@posting.google. com>
Old Wolf <ol*****@inspire.net.nz> writs:
ITYM:
printf("%lf", n);


This is well-defined in C99, and does the same as using "%f", but
in C89 the combination of the "l" modifier with any of the floating
point formats in printf (e, E, f, g, and G) is technically undefined.

You always need the l in %lf when using scanf() on "double"s, but
in C89, you should not use the l modifier. The printf() and scanf()
functions are not as symmetric as they might first appear. This
false symmetry begins with the fact that scanf() takes the addresses
of the objects it fills in, and continues with %f vs %lf and gets
even more asymmetric with the behavior of %* directives. In printf,
for instance, %*d requires two int values and prints the second
using the first as a field width, but in scanf, %*d requires zero
pointers and skips the assignment of an "int" conversion.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Kostatus | last post by:
I have a virtual function in a base class, which is then overwritten by a function of the same name in a publically derived class. When I call the function using a pointer to the derived class...
4
by: andy | last post by:
i am coding a dll which contains a function take a const wchar_t* as parameter, call it form a exe, the wchar_t is passed to dll function, but the function in dll will then call another function...
3
by: Jan-Henrik Grobe | last post by:
Hallo, I am coming to this newsgroup with a very strange Problem. I have two c++ files A.cpp and B.cpp....In A.cpp I am creating an openGL window and in B.cpp I have stored the callback...
2
by: Hennie de Nooijer | last post by:
Because of an error in google or underlying site i can reply on my own issue. Therefore i copied the former entered message in this message....
18
by: jimfortune | last post by:
I have an A97 module called modWorkdayFunctions in: http://www.oakland.edu/~fortune/WorkdayFunctions.zip It allows the counting of workdays taking into consideration up to 11 U.S. holidays. ...
4
by: Andy_Khosravi | last post by:
Hello, I'm having a problem with the MID function within Access 97. I have been trying to build a function to check to make sure that a field on a form does not have any spaces or dashes. This...
7
by: Mike D. | last post by:
I have a problem with a dynamic library I am developing, but it is really more of a pointer issue than anything else. Hopefully someone here can lend me some assistance or insight into resolving...
2
by: Fernando Barsoba | last post by:
Dear all, I have been posting about a problem trying to encrypt certain data using HMAC-SHA1 functions. I posted that my problem was solved, but unfortunately, I was being overly optimistic. I...
78
by: Josiah Manson | last post by:
I found that I was repeating the same couple of lines over and over in a function and decided to split those lines into a nested function after copying one too many minor changes all over. The only...
6
by: RandomElle | last post by:
Hi there I'm hoping someone can help me out with the use of the Eval function. I am using Access2003 under WinXP Pro. I can successfully use the Eval function and get it to call any function with...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.