473,806 Members | 2,878 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

tanjent function - can someone check my code

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

int i=0, j=0, *z=0;
double tanjent=0.0;

void main(int *)
{

for(;;)
{
tanjent[&z] = sin(i) / cos (j);
*z=&z+1

}

printf(tanjent[k],"%d);
return &z;

}

Regards,
Zach

Nov 14 '05 #1
17 1409
Zach wrote:
[snip]

I think I see a troll.

--
Thomas.
Nov 14 '05 #2
no! i am not at troll - how rude.
i posted my code and asked for feedback.
if you cannot reply constructively please dont reply accusing people of
trolling when they arent!

zach

Nov 14 '05 #3

Zach wrote:
no! i am not at troll - how rude.
i posted my code and asked for feedback.
if you cannot reply constructively please dont reply accusing people of trolling when they arent!

You aren't helping yourself much with this whiny tirade. There are so
many weird things in your code that it's pretty reasonable to suspect
it's some sort of troll.

You don't explain what problems you have. It's obvious that you didn't
compile it. Here are a few questions:

1. What do you think this does?
*z=&z+1

2. Where did k come from?

3. What do you think the result of dividing 0 by 0 would be?

4. What does this declare?
*z=0;

5. What is this?
&z
Brian

Nov 14 '05 #4

Zach wrote:
no! i am not at troll - how rude.
i posted my code and asked for feedback.
if you cannot reply constructively please dont reply accusing people of trolling when they arent!


You aren't helping yourself much with this whiny tirade. There are so
many weird things in your code that it's pretty reasonable to suspect
it's some sort of troll.

You don't explain what problems you have. It's obvious that you didn't
compile it. Here are a few questions:

1. What do you think this does?
*z=&z+1

2. Where did k come from?

3. How would i and j be anything but 0?

4. What does this declare?
*z=0;

5. What is this?
&z

6. What does this do?
for(;;)
Brian

Nov 14 '05 #5
Zach wrote:

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

int i=0, j=0, *z=0;
double tanjent=0.0;

1> void main(int *)
{
for(;;)
{
2> tanjent[&z] = sin(i) / cos (j);
3> *z=&z+1
}
4> printf(tanjent[k],"%d);
5> return &z;
}


1> main returns int, and has parameters of type int and char**
2> attempt to index NULL, doomed.
2> sin(0) / cos(0) == 0 / 1 == 0
3> attempt to store a pointer in an int. No final semi.
4> Bad arguments to printf, and unterminated string. k undeclared.
5> returning a pointer in place of an int.

The "for(;;)" line is correct, as are the isolated braces. So I
would say it falls a tad short of perfection. Your compiler should
have showed these up.

[1] c:\c\junk>cc junk.c
junk.c:8: warning: return type of `main' is not `int'
junk.c:8: warning: first argument of `main' should be `int'
junk.c:8: warning: `main' takes only zero or two arguments
junk.c: In function `main':
junk.c:7: parameter name omitted
junk.c:11: subscripted value is neither array nor pointer
junk.c:13: warning: assignment makes integer from pointer without a
cast
junk.c:13: parse error before '}' token
junk.c:14:21: warning: multi-line string literals are deprecated
junk.c:14:21: missing terminating " character
junk.c:14:21: possible start of unterminated string literal
--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Nov 14 '05 #6
Zach wrote:
no! i am not at troll - how rude.
i posted my code and asked for feedback.
if you cannot reply constructively please dont reply accusing people of
trolling when they arent!


This is as constructive as I can be:

Start learning C from scratch. Again. You might find it
easier the second time around. Your code is so wrong that
I find it hard to believe that it is not deliberate.

--
Thomas, took the bait once. And only once.
Nov 14 '05 #7
CBFalconer wrote:
Zach wrote:
#include <stdio.h>
#include <math.h>

int i=0, j=0, *z=0;
double tanjent=0.0;

1> void main(int *)
{
for(;;)
{
2> tanjent[&z] = sin(i) / cos (j);
3> *z=&z+1
}
4> printf(tanjent[k],"%d);
5> return &z;
}

1> main returns int, and has parameters of type int and char**
2> attempt to index NULL, doomed.
2> sin(0) / cos(0) == 0 / 1 == 0
3> attempt to store a pointer in an int. No final semi.
4> Bad arguments to printf, and unterminated string. k undeclared.
5> returning a pointer in place of an int.

The "for(;;)" line is correct, as are the isolated braces. So I
would say it falls a tad short of perfection. Your compiler should
have showed these up.


Here are some additional items:
1. The "for" loop is infinite and the printf and return will
never be executed.

2. The code inside the "for" loop will, after writing to address 0,
will continue to write to entire address space of the platform,
providing that the operating system and processor allow it.

3. The "tanjent" variable is one double precision value.
The "for" loop treats it as an array.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.l earn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library

Nov 14 '05 #8
Hi,

I wish to make an iterative program that uses recursion to continually
calculate the value of tanjent function and store the values in an
array. I wished to use z as return argument and have it passed back to
main and main gets called again and again yet with value being
increased each time.

Thanks for feedback!
zach

Nov 14 '05 #9
"Zach" <ne****@gmail.c om> writes:
I wish to make an iterative program that uses recursion to continually
calculate the value of tanjent function and store the values in an
array.
Why do you want to use recursion?
I wished to use z as return argument and have it passed back to
main and main gets called again and again yet with value being
increased each time.


Calling main recursively is rarely useful.

(BTW, it's spelled "tangent", not "tanjent".)

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #10

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

Similar topics

14
11697
by: deancoo | last post by:
Hello all, I have a class member, which calls another member from the same class. The problem I'm experiencing is that the nested function executes fine, but causes a segmentation fault as it exits. I've traced it to the point in the code just before the line following the nested function is to be called, or conversely right after the last line of the nested function. What might be my problem? I'm hoping someone can give me some...
8
4835
by: Falc2199 | last post by:
Hi, Does anyone know how to make this work? var sectionId = 5; repeat_section_sectionId(); function repeat_section_5(){ alert("firing"); }
17
1442
by: Michael | last post by:
Hi, Could you pleaes let me know when I need to use virtual destctor function in the base class? Thanks in advance, Michael
4
1456
by: hanseymoon | last post by:
Dear newsgroup: I've got this long function, which works good overall to spell check words from a dictionary and I am not in a position to replace it. Can someone please see where or how it might be chopping up words like: don't. It brings them back as: 't, chopping off the "don" before the apostrophe. I've looked over the whole situation and ran many $string tests....and it appears to be narrowed it down to this. I may be wrong and...
28
4720
by: Bill | last post by:
Hello All, I am trying to pass a struct to a function. How would that best be accomplished? Thanks, Bill
13
4104
by: Peter Michaux | last post by:
encodeURIComponent is commonly used to serialize forms for use with XMLHttpRequest requests. For a perfect simulation of browser form requests, the goal is to serialize form data in the <URL: http://www.w3.org/TR/1999/REC-html401-19991224/interact/forms.html#h-17.13.4.1> application/x-www-form-urlencoded</astandardized format. The handling of whitespace by encodeURIComponent() is different from the x-www-form-urlencoded standard....
44
7870
by: climber.cui | last post by:
Hi all, Does anyone have experience on the thread-safty issue with malloc()? Some people said this function provided in stdlib.h is not thread- safe, but someone said it is thread safe. Is it possible this function evolves from thread-unsafe to thread-safe in recent years? How could i find out? I am using the C library coming with GNU linux distribution. thanks a lot.
55
3337
by: lovecreatesbea... | last post by:
Do you check all error conditions for all library calls in you code? Is it necessary to check all errors? Is it convenient to check all errors (or how to make code clean and readable with mass of non business logic related code block)? The following code from net-snmp library calls atoi five times but checks none. Do we code a wrapper my_atoi_with_error_check() around atoi and call this new one everywhere else? Is it a good practice...
3
1696
by: gmdune | last post by:
Hi All, I have written a program that doesn't seem to work and I can't figure out why it's not working. It compiles correctly, but when I run it I get prompted by the first couple of printf statements, as it should, but then the rest of the code doesn't run. Could someone please help me? Thanks for your help! #include <stdio.h>
0
9719
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10618
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10371
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10110
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9187
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6877
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3850
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.