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

J

JS

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
 
A

Alf P. Steinbach

* 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).
 
V

Victor Bazarov

JS said:
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
 
H

Howard

JS said:
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
 
D

Default User

JS said:
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
 
R

Roger

JS said:
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
 
J

JS

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,790
Messages
2,569,637
Members
45,346
Latest member
EstebanCoa

Latest Threads

Top