Need Help Getting Started with C Programming?

In summary, Warren has been programming for two and a half years, and is planning to take the accelerated intro to C course at the University of Toronto this fall. He recommends that beginners get started by taking a look at the standard library that comes with C, familiarizing themselves with pointers and pointer arithmetic, and getting used to working in an environment with Unix-like system commands. He also recommends using a text editor such as TextPad or nedit. He is not sure if he will need to download a C compiler, but recommends using one that is capable of compiling C++.
  • #1
rocketboy
243
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.

Thanks!
 
Technology news on Phys.org
  • #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!
 
  • #3
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
 
  • #4
Thanks to both of you.

What text editors do you use?
 
  • #5
I use one called TextPad on Windows, and one called nedit on Unix.

- Warren
 
  • #6
i use http://notepad-plus.sourceforge.net/uk/site.htm" 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 that's the best IDE out there, though the compiler doesn't stand in all the standards).
 
Last edited by a moderator:
  • #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?

Thanks.
 

Attachments

  • cygwin screen.jpg
    cygwin screen.jpg
    34.5 KB · Views: 464
Last edited:
  • #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?
 
  • #9
Hmm... I was 99% sure that Cygwin included gcc by default. Try g++ instead:

g++ -o hello hello.c

- Warren
 
  • #10
neurocomp2003 said:
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?

Yes I am. Are you an N-Psi student?
 
  • #11
nope..i just have abuddy that might want to to take that course...whats the course like? is it really learn at your own pace?
 
  • #12
neurocomp2003 said:
nope..i just have abuddy that might want to to take that course...whats the course like? is it really learn at your own pace?

I don't know, I'm going to be a freshman in september. I just graduated from high school.
 
  • #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?
 
  • #14
C++ is essentially an expanded version of C. All C++ compilers are capable of compiling C. Visual C++ includes such a compiler.

- Warren
 
  • #15
chroot said:
C++ is essentially an expanded version of C. All C++ compilers are capable of compiling C. Visual C++ includes such a compiler.

- Warren

Awesome, now if only microsoft would stop being a... and allow me to install it... but noooo, i need SP2 first...:devil:
 
  • #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! EDIT: nevermind, I fixed it and it's now installed. Woohoo!
 
Last edited:
  • #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.
 
  • #18
chroot said:
C++ is essentially an expanded version of C. All C++ compilers are capable of compiling C. Visual C++ includes such a compiler.

- Warren

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:
  • #19
graphic7,

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
 
  • #20
rocketboy said:
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?

Thanks.

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.
 

1. What is C programming and why is it important?

C programming is a high-level programming language that is widely used in the development of software and operating systems. It is important because it allows programmers to write efficient and portable code that can run on different platforms.

2. What are the basic components of a C program?

A C program is made up of functions, variables, data types, operators, control structures, and input/output statements. These components work together to create a program that can perform specific tasks and solve problems.

3. How do I declare and initialize variables in C?

In C, variables must be declared before they can be used in a program. This is done by specifying the data type and name of the variable. Variables can also be initialized, or given an initial value, at the time of declaration or later in the program using assignment statements.

4. What is the difference between a compiler and an interpreter in C programming?

A compiler is a program that translates the entire source code of a program into machine code before it is executed. An interpreter, on the other hand, translates and executes the code line by line. This means that a compiler produces a standalone executable file, while an interpreter requires the presence of the interpreter program to run the code.

5. What are the common data types in C programming?

The common data types in C programming include int (integer), float (floating-point number), char (character), double (double-precision floating-point number), and void (no value). These data types are used to store different types of data and are important for performing mathematical operations and manipulating data in a program.

Similar threads

  • Programming and Computer Science
Replies
2
Views
768
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
2
Views
503
  • Programming and Computer Science
Replies
11
Views
2K
  • Programming and Computer Science
Replies
14
Views
1K
  • Programming and Computer Science
Replies
9
Views
1K
  • Programming and Computer Science
2
Replies
65
Views
2K
  • Programming and Computer Science
Replies
19
Views
3K
  • Programming and Computer Science
Replies
16
Views
1K
Back
Top