Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > stuck

Reply
Thread Tools

stuck

 
 
Bill Cunningham
Guest
Posts: n/a
 
      01-18-2011
osmium wrote:

> You could compute the desired result for all four good cases and pass
> that value to a function that prints it.
>
> Something like:
>
> in oper():
> double result;
> ...
> if(c == 'a')
> result = x+y;
> // other three cases plus error detection case
> ...
> print(result);


Do you mean printf here?

> return result;
>
> void print(double arg)
> {
> printf( fromat_stuff, arg); // note lack of return statement
> }
> ---------------
> I don't know if that helps or not. If not code something up and post
> it.



 
Reply With Quote
 
 
 
 
osmium
Guest
Posts: n/a
 
      01-18-2011
"Bill Cunningham" wrote:

> osmium wrote:
>
>> You could compute the desired result for all four good cases and pass
>> that value to a function that prints it.
>>
>> Something like:
>>
>> in oper():
>> double result;
>> ...
>> if(c == 'a')
>> result = x+y;
>> // other three cases plus error detection case
>> ...
>> print(result);

>
> Do you mean printf here?


No, this is a call to the function that *you* provide. As I understand you,
you wanted to prove you could kind of "hide" the call to printf - which is
later. This hides it by adding an (unnecessary) level of indirection..

Try it and see if it is what you want. If you didn't want to hide it,
reread the message you sent me about what you are trying to do. BTW, you
asked if it made sense and I didn't answer. No it doesn't make sense; but
students often do things that don't make sense to prove some point or other.


 
Reply With Quote
 
 
 
 
Bill Cunningham
Guest
Posts: n/a
 
      01-19-2011
osmium wrote:

> No, this is a call to the function that *you* provide. As I
> understand you, you wanted to prove you could kind of "hide" the call
> to printf - which is later. This hides it by adding an (unnecessary)
> level of indirection..


Yes.

> Try it and see if it is what you want. If you didn't want to hide it,
> reread the message you sent me about what you are trying to do. BTW,
> you asked if it made sense and I didn't answer. No it doesn't make
> sense; but students often do things that don't make sense to prove
> some point or other.


Ok I think my question has been or is being answered and I will try
these tips and go on. If this works properly and I run into other problems
and retry and retry them and I just can't find the solution I will come to
the group.
Thanks.


 
Reply With Quote
 
Nick Keighley
Guest
Posts: n/a
 
      01-22-2011
On Jan 17, 9:14*pm, "osmium" <(E-Mail Removed)> wrote:
> "Niklas Holsti" wrote:
> > Bill Cunningham wrote:


> >> * * I have these two functions one calls the other one. I have tried
> >> everything to debug them except a damn debugger.


why haven't you used a debugger?


> >>I have placed puts
> >> messages at all the return and I still get two numbers on my screen.
> >> What's wrong with this code?

>
> > Whether the code is wrong or right depends on what you want it to do,
> > which you haven't said -- yet.

>
> This is a persistent problem, Bill. *[Can] you complete the comments I have
> added? *I can *almost* figure out what oper() is supposed to do, then it
> calls vop() for some reason unknown to me and I am baffled. I think you
> wanted to print something but wanted to do it indirectly. *Might a macro be
> be usefull here? *Is the object to save typing? *Or what?
>
> // This function ....


that is, bill, he wants you to document what the function does (or is
supposed to do).


> >> double oper(char c, double x, double y)
> >> {
> >> * * if (c == 'a')
> >> * * * * return vop(x + y);
> >> * * else if (c == 's') {
> >> * * * * return vop(x - y);
> >> * * } else if (c == 'm') {
> >> * * * * return vop(x * y);
> >> * * } else if (c == 'd') {
> >> * * * * return vop(x / y);
> >> * * } else {
> >> * * * * fputs("usage error\n", stderr);
> >> * * * * return -1;
> >> * * }
> >> * * return 0;

>
> // This fucntion ...>> double vop(double oper)
> >> {
> >> * * return printf("%.2f\n",oper);
> >> * }

>
> Why overuse identifiers? There are plenty of unique identifiers to go
> around, and uniqueness adds clarity.


I don't see that it necessaily does. Are all the parameter names
unique in the standard library?

> *In other words:
>
> double vop(double abc)
> * *{
> * *retrun printf("%.2f\n", abc):
> * *}
> would be less confusing.


not significantly. Though having a function and a variable with the
same name is a bit odd. I think bill would be better using longer more
descriptive function names. Though that would involve him thinking
about the program and he's historically reluctent to do this (or he's
trolling).

<snip>
 
Reply With Quote
 
ec429
Guest
Posts: n/a
 
      01-22-2011
On 22/01/11 14:51, Nick Keighley wrote:
>> // This fucntion ...
>> double vop(double oper)
>>>> {
>>>> return printf("%.2f\n",oper);
>>>> }

>>
>> Why overuse identifiers? There are plenty of unique identifiers to go
>> around, and uniqueness adds clarity.

>
> I don't see that it necessaily does. Are all the parameter names
> unique in the standard library?

No, but more relevantly none (afaik) of the parameter names in the
standard library are also names of functions in the standard library;
similarly, none of the parameter names are also names of static
variables. (Of course, a static variable and a function can't have the
same name (assuming they're in the same compilation unit, or something))
In other words, identifiers generally shouldn't override each other; two
identifiers shouldn't have the same name if their scopes overlap
(typically, the scope of one being a subset of the scope of the other).
After all, it can get quite confusing when you wonder why some code
hasn't modified 'i', say, and don't realise that it's declared another
'i' in tighter scope.
Ultimately it's a coding style thing, and therefore subjective. But it
does make a lot of sense.
-Edward
--
'sane', adj.: see 'unimaginative'
on the web - http://jttlov.no-ip.org
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dlink di-784 freezing / lights stuck on markm75c@msn.com Wireless Networking 6 07-05-2006 03:36 PM
Wireless Network Connection Stuck on "Acquiring Network Address" =?Utf-8?B?bmlja3Nwb29u?= Wireless Networking 4 10-20-2005 07:31 AM
Clearing stuck dialog in Firefox Splibbilla Firefox 0 04-09-2005 09:34 AM
stuck sending message SightSeer Firefox 4 02-07-2005 12:19 PM
Mozilla stuck in German! RHertz Firefox 2 07-27-2004 12:54 AM



Advertisments