f



How to compile this C Code in Dev-C++??

I have done the following: New Project -> Console Application -> C Project.

Then I get the following text:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{

  system("PAUSE");
  return 0;
}


But where do I write my own C code? I have written the following code:

void c(unsigned int n) {
 while (n > 1)
  if ((n & 1) == 0)
  n = n/2;
  else
  n = 3 * n + 1;
}

But where should I put it and how do I compile it?

js



0
JS
11/18/2004 5:57:13 PM
comp.lang.c++ 49423 articles. 7 followers. Post Follow

6 Replies
720 Views

Similar Articles

[PageSpeed] 45

* JS:
> I have done the following: New Project -> Console Application -> C Project.

Off-topic on two grounds: (1) this is a C++ group, and questions about
pure C are off-topic, and (2) this is a C++ group, and platform-specific
questions are off-topic.

Due to (2) the question is also off-topic in [comp.lang.c].

Try [alt.comp.lang.learn.c.c++]; you might be well advised to first
check out the FAQ for that group (Google).


-- 
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
0
alfps (7389)
11/18/2004 6:37:44 PM
JS wrote:
> I have done the following: New Project -> Console Application -> C Project.
> 
> Then I get the following text:
> 
> #include <stdio.h>
> #include <stdlib.h>
> 
> int main(int argc, char *argv[])
> {
> 
>   system("PAUSE");
>   return 0;
> }
> 
> 
> But where do I write my own C code? I have written the following code:
> 
> void c(unsigned int n) {
>  while (n > 1)
>   if ((n & 1) == 0)
>   n = n/2;
>   else
>   n = 3 * n + 1;
> }
> 
> But where should I put it and how do I compile it?

I think you're in a wrong newsgroup, twice.  First, because this is not
a C newsgroup, but a C++ newsgroup.  comp.lang.c is just down the hall,
to the left.  Second, because you probably need help with using your IDE
and not with the language.  I don't know a newsgroup for it.  Isn't there
an online (Web) forum for Dev-C++ somewhere?

V
0
v.Abazarov (13256)
11/18/2004 6:38:25 PM
"JS" <dsa.@asdf.com> wrote in message news:cninmd$njr$1@news.net.uni-c.dk...
>I have done the following: New Project -> Console Application -> C Project.
>
> Then I get the following text:
>
> #include <stdio.h>
> #include <stdlib.h>
>
> int main(int argc, char *argv[])
> {
>
>  system("PAUSE");
>  return 0;
> }
>
>
> But where do I write my own C code? I have written the following code:
>
> void c(unsigned int n) {
> while (n > 1)
>  if ((n & 1) == 0)
>  n = n/2;
>  else
>  n = 3 * n + 1;
> }
>
> But where should I put it and how do I compile it?
>

As you've been told already, you should ask C questions in a C newsgroup.

But, this could just as easily be a C++ question, so I'll give you some 
pointers:

First, one place to put that function is just above your main() function. 
Then, you can call it from main().  There are other ways to arrange 
programs, which you'll need to learn, but this will work for now.

Second, leaving aside analysis of what the function c does internally, you 
should note that anything that it does to n internally will not be relected 
back to the variable that is passed to the function, because n, in that 
function, is simply a local copy of the value passed in.  That's because you 
passed it "by value".  If you want to actually change the value that was 
passed in (from main, for example), you'll need to pass it "by reference".

-Howard



0
alicebt (1862)
11/18/2004 6:49:52 PM
JS wrote:

> I have done the following: New Project -> Console Application -> C
> Project.
> 
> Then I get the following text:
> 
> #include <stdio.h>
> #include <stdlib.h>
> 
> int main(int argc, char *argv[])
> {
> 
>   system("PAUSE");
>   return 0;
> }
> 
> 
> But where do I write my own C code? I have written the following code:
> 
> void c(unsigned int n) {
>  while (n > 1)
>   if ((n & 1) == 0)
>   n = n/2;
>   else
>   n = 3 * n + 1;
> }
> 
> But where should I put it and how do I compile it?


What textbook are you using that doesn't explain how a program in
structured?




Brian
0
first.last3 (701)
11/18/2004 6:53:36 PM
"JS" <dsa.@asdf.com> skrev i meddelandet 
news:cninmd$njr$1@news.net.uni-c.dk...
>I have done the following: New Project -> Console Application -> C Project.
>
> Then I get the following text:
>
> #include <stdio.h>
> #include <stdlib.h>
>
> int main(int argc, char *argv[])
> {
>
>  system("PAUSE");
>  return 0;
> }
>
>
> But where do I write my own C code? I have written the following code:
>
> void c(unsigned int n) {
> while (n > 1)
>  if ((n & 1) == 0)
>  n = n/2;
>  else
>  n = 3 * n + 1;
> }
>
> But where should I put it and how do I compile it?
>
> js

Try this forum
http://sourceforge.net/forum/forum.php?forum_id=48211 


0
11/18/2004 7:40:23 PM
Sorry for my offtopic post but I am totally new to C/C++/Pure C. But thank
you for the guidelines I will follow some of the advises you gave me.

js


0
JS
11/18/2004 8:34:06 PM
Reply: