|
no question yet
Maybe I'll put more info: 1- I'll be compsci major 2- I'm not entirely new to programming + Show Spoiler [solved_ones] +======================= Question: The while loop calls recursively on itself automatically right? That's pretty interesting. I remember in scheme I had to do (define (function args) (if (condition) then (function (modifyer args))) but I guess in C it's done internally and I don't have to call it again xD ================================ ======================== I tried to name my program "program" so I did # include <stdio.h> program() yadayada... But when I tried to compile my code I get evan@Evan-Box:~/Documents/tryingout$ cc temperature.c /usr/lib/gcc/x86_64-linux-gnu/4.3.2/../../../../lib/crt1.o: In function `_start': (.text+0x20): undefined reference to `main' collect2: ld returned 1 exit status evan@Evan-Box:~/Documents/tryingout$ ls temperature.c temperature.c~ yada.c yada.c~ So does that mean I cannot name my program anything but main(args) or what? ===================== So i'll be working a lot with C so I guess I'll just keep updating this blog. I'll put all solved problems in the solved section in a spoiler and post new ones as they arise.
|
main() is special: it's where the program knows to start... otherwise it won't compile into an executable program
|
main(args) is not the name of a program. That is a function definition. Every program needs a main function. This is the place your program will begin execution at.
|
I have no experience with C, but some with C++, Java, and Flash. From what I have learned the program can be named anything but there needs to be a main method. What the program is called is usually what the name it is saved as is. In C++ you can have a Class that defines an object named whatever you want but somewhere in the program you still need a Main method that executes your code.
|
in C++, i learned #includes using namespace std; int main() {
i'm guessing you are missing the C version of 'int main()' or something that is similar??
|
|
Why are you learning C? :3 There are much better languages for beginners ;P
|
C is great as a beginner language for CompSci. I believe that pointers, memory management, data structures, etc is a very important aspect to CompSci. Don't get me wrong, I'm a Java developer (program for living) but I did learn all the low level (C, assembly) stuff in the past. It's very important to have a strong base before going out there developing in high level languages and thinking that everything that's happening under the hood is magic lol.
|
On January 08 2009 13:28 FreeZEternal wrote: C is great as a beginner language for CompSci. I believe that pointers, memory management, etc is a very important aspect to CompSci. Don't get me wrong, I'm a Java developer (program for living) but I did learn all the low level (C, assembly) stuff in the past. It's very important to have a strong base before going out there developing in high level languages and thinking that everything that's happening under the hood is magic lol. C is a high level language. It does allow you do have great control over a lot of low level stuff, but it doesn't compare to assembly.
|
On January 08 2009 13:01 InRaged wrote: Why are you learning C? :3 There are much better languages for beginners ;P
I started learning C++ when i was in 6th grade so I'm sure he will have no problem learning C.
|
Earlier I saw you having problems running compiled programs, this is due to rights management in linux. To run your compiled program, when in the directory, just type ./programname
Say you compiled program.c to program.out, typing ./program.out will run your program, as opposed to type ~/long/ass/path/to/program
In linux, each directory has two special "directories" that are links. the first is "." (dot) and the second is ".." (dot dot).
. is used to refer to your current working directory .. is used to refer to the directory above your current working directory
If you are in /home/evan/porno "cd ." will move you to /home/evan/porno "cd .." will move you to /home/evan
Anyways, the point - Programs that are not given rights to execute globaly (see chmod and rights management) have to be executed with a path before the name - ie "./" or "/long ass path"
Im horrible at explaining.
|
also if your main function is an int type, you should probably end by returning an integer (I don't think it fails if you don't include it, but int type functions should return ints) you can (I think in C) have void main (), but my professor frowned on that (I think some compilers wont recognize it, but I don't really remember if that was why)
so
#include.... using namespace std;
int main () {
//code goes here
return 0; }
kind of neat that you guys are using C, I thought everyone had switched over to using C++ and Java for compsci.
I started my assembly course today. pretty scared
|
There are so many variants and standards of C so it's good to always code according to some sort of standard.
|
United States17042 Posts
On January 08 2009 13:39 b3h47pte wrote:Show nested quote +On January 08 2009 13:01 InRaged wrote: Why are you learning C? :3 There are much better languages for beginners ;P I started learning C++ when i was in 6th grade so I'm sure he will have no problem learning C.
C is really really good to learn depending on what you actually want to do. Embedded systems all use C, just because they tend to be speed dependent, and you're memory/processor constrained. C runs pretty fast (not like hand optimized coding "to the metal", but close enough ><;
|
On January 08 2009 13:28 FreeZEternal wrote: C is great as a beginner language for CompSci. I believe that pointers, memory management, data structures, etc is a very important aspect to CompSci. Don't get me wrong, I'm a Java developer (program for living) but I did learn all the low level (C, assembly) stuff in the past. It's very important to have a strong base before going out there developing in high level languages and thinking that everything that's happening under the hood is magic lol. If that's for CompSci, then no questions. I thought maybe it's just for hobby or whatever ;P
On January 08 2009 11:30 evanthebouncy! wrote: Question: The while loop calls recursively on itself automatically right? Well, yes and no :3 Practically, it rarely matters, but you shouldn't call it recursion, because it isn't at all.
|
On January 08 2009 16:25 InRaged wrote:Show nested quote +On January 08 2009 13:28 FreeZEternal wrote: C is great as a beginner language for CompSci. I believe that pointers, memory management, data structures, etc is a very important aspect to CompSci. Don't get me wrong, I'm a Java developer (program for living) but I did learn all the low level (C, assembly) stuff in the past. It's very important to have a strong base before going out there developing in high level languages and thinking that everything that's happening under the hood is magic lol. If that's for CompSci, then no questions. I thought maybe it's just for hobby or whatever ;P Show nested quote +On January 08 2009 11:30 evanthebouncy! wrote: Question: The while loop calls recursively on itself automatically right? Well, yes and no :3 Practically, it rarely matters, but you shouldn't call it recursion, because it isn't at all.
Really? Suppose I want to make a while loop in scheme, that does what the while loop does in C, I would write it with recursion.
|
I don't know how it is in other languages, but recursion in C/C++ is a function calling itself repeatedly with modified parameters until it's finished doing what it has to do. This is a Bad Thing in most instances because each function call generates a new stack, but stacks aren't disposed of until a function has returned.
While loops are language constructs which can be much more accurately compared to iteration. Iteration is much cooler than recursion. If your comp sci professor tells you differently (as he actually did to a mate of mine) then he is a moron.
While loops just take an exit condition and execute the same code over and over until that condition is met.
I'm drunk, sorry.
|
On January 08 2009 19:12 fonger wrote: I don't know how it is in other languages, but recursion in C/C++ is a function calling itself repeatedly with modified parameters until it's finished doing what it has to do. This is a Bad Thing in most instances because each function call generates a new stack, but stacks aren't disposed of until a function has returned.
While loops are language constructs which can be much more accurately compared to iteration. Iteration is much cooler than recursion. If your comp sci professor tells you differently (as he actually did to a mate of mine) then he is a moron.
While loops just take an exit condition and execute the same code over and over until that condition is met.
I'm drunk, sorry.
Haha iteration is probably the answer i"m looking for. but iteration is not much cooler than recursion :p
|
you should get a job teaching comp sci then
there seems to be a lot of demand for you idiots :D
|
Sydney2287 Posts
My professor would say that recursion tends to be the more 'elegant' solution, but is never better than iteration.
|
|
|
|