Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C Programming necessities

  1. Jul 25, 2006 #1
    Hey everyone,

    I have programmed in Java for 2.5 years (prior to last year which I did no programming, because I did the gr 12 course in grade 11 and there weren't any more courses for me to do in grade 12).

    Next year I will be going to Univ. of Toronto for Engineering Science, and in the computers course I will be programming in C. I decided I wanted to get a head start this summer, using online tutorials and playing around with the language, which I figure shouldn't be too difficult to do.

    The problem is I need to get started. What compiler do you guys use and also what programs do you recommend for text editing when writing C? For Java I used an IDE called "Eclipse", and I found a C plugin for it but to be honest I have no idea how to use this.

    Also, what is the basic structure of a C program? In java all you needed for hello world was your .java file, which could be put through the Java compiler and run. In Eclipse when I told it to create a new C project it created multiple file extensions, and I must say I was somewhat confused.

  2. jcsd
  3. Jul 25, 2006 #2
    Well if you a used to Java then C should be easy from a programming structure perspective. Java is way more structured and IMHO a much better programming language in terms of structure.

    But C has it own advantages, it is much faster and way more flexible, and it is lower level.
    I would recommend you familiarize yourself with the different kind of variables that are used in C and how they relate to the memory architectures of computer first. Second you should make yourself familiar with pointers and pointer arithmetic. If you want to be a good C programmer then using pointer manipulations should be second nature! It is also a good idea to look at the standard library that comes with C.

    With regards to the environment I would check what they will use at the university and stick with that. If they run Unix/Linux then practice in that environment otherwise use a windows based compiler.

    With your knowledge of Java and later C you should have no great difficulties using C++ as well.

    Have fun!
  4. Jul 25, 2006 #3


    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Download and install Cygwin, which includes a C compiler.

    Use your favorite text editor to write up a small C program.

    Open the Cygwin bash shell, and type the command:

    gcc -o hello hello.c

    This command compiles the source file "hello.c" into the executable file "hello."

    Then, run the executable by typing "./hello"

    - Warren
  5. Jul 25, 2006 #4
    Thanks to both of you.

    What text editors do you use?
  6. Jul 25, 2006 #5


    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    I use one called TextPad on Windows, and one called nedit on Unix.

    - Warren
  7. Jul 25, 2006 #6
    i use notepad++ for windows, and gedit for linux.

    though if you wish to use an IDE, to manage a project and use auto-complete, there's "bloodshed devC++", "code::blocks", and visual studio is now free for non-commercial use! (most people say thats the best IDE out there, though the compiler doesn't stand in all the standards).
    Last edited: Jul 25, 2006
  8. Jul 25, 2006 #7
    Cygwin is telling me that it doesn't recognize the command "gcc"

    Perhaps I didn't include the proper packages when installing? I simply accepted the settings that it included, not knowing what was what.

    Also, how do you specify the directory that your C program is stored in?


    Attached Files:

    Last edited: Jul 25, 2006
  9. Jul 25, 2006 #8
    i use the VC6.0++ only for its GUI look. However it is not free. Don't really like the VC.net environment because they took away the workspace and all the shortkeys are different.

    rocketboy: Are you taking teh accelerated intro to C Course at UFT?
  10. Jul 25, 2006 #9


    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Hmm... I was 99% sure that Cygwin included gcc by default. Try g++ instead:

    g++ -o hello hello.c

    - Warren
  11. Jul 25, 2006 #10
    Yes I am. Are you an N-Psi student?
  12. Jul 25, 2006 #11
    nope..i just have abuddy that might wanna to take that course...whats the course like? is it really learn at your own pace?
  13. Jul 25, 2006 #12
    I don't know, I'm going to be a freshman in september. I just graduated from high school.
  14. Jul 25, 2006 #13
    Can I use Visual C++ to program in C? I mean, will I need to download a C compiler or will it be included?
  15. Jul 25, 2006 #14


    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    C++ is essentially an expanded version of C. All C++ compilers are capable of compiling C. Visual C++ includes such a compiler.

    - Warren
  16. Jul 25, 2006 #15
    Awesome, now if only microsoft would stop being a.... and allow me to install it... but noooo, i need SP2 first...:devil:
  17. Jul 25, 2006 #16
    wow you're kidding me. VC++ has to install microsoft .NET framework 2.0 first, and apparently there is a problem with windows installer and it gives me an error everytime I attempt it. I even tried downloading and installing the .NET framework independantly!:surprised

    EDIT: nevermind, I fixed it and it's now installed. Woohoo!
    Last edited: Jul 25, 2006
  18. Jul 26, 2006 #17
    Unlike Java C does not have a garbage collector so you must handle allocation and deallocation of memory yourself. Study pointers, dynamic allocation and deallocation of memory, difference between memory on the heap and on the stack, etc. With a sound understanding of how all this works you will most likely avoid many headaches.

    A good C reference manual such as "C: A Reference Manual (5th Edition)" by Samuel P. Harbison and Guy L. Steele is a big help.

    The C plugin for Eclipse (CDT) isn't all that bad. Look on the plugin website or google for examples on using it to get started.
  19. Aug 5, 2006 #18


    User Avatar
    Gold Member

    Not true. C++ adds several additional reserved words that would prevent successful compilation of C code that used these reserved words. Also, C++ comments can produce unexpected behaviours between your C and C++ code.

    For example:

    "x //* y
    //*/ y"

    results in x / y for C and just x for C++.

    (Odd, the code I've writted does not appear to be displaying correctly. Try quoting me to look at the code.)
    Last edited: Aug 5, 2006
  20. Aug 5, 2006 #19


    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member


    I said "essentially." Obviously the presence of double slashes in your code would be misinterpreted by the C++ compiler to be single-line comments, but that's obviously a pretty contrived example.

    In general, most C++ compilers also include an ANSI C mode, which, of course, guarantees compliance (including comments) with the ANSI C standards.

    - Warren
  21. Aug 5, 2006 #20
    You probably need to rerun the cygwin setup program to select gcc. Once it's installed and you're in the cygwin shell, it should already be in your path. However, it won't work if you try to run it from a regular windows console.

    Others have recommended dev-c++, and this includes mingw32, which is a port of gcc to win32.

    Cygwin does give you a convenient unixy environment, with lots of available utilities. However, you might consider trying Ubuntu Linux. The live CD is also the installer, and it's a breeze to install.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: C Programming necessities
  1. C program (Replies: 4)

  2. C program (Replies: 4)

  3. C Program (Replies: 3)

  4. C program (Replies: 0)

  5. C programming (Replies: 9)