c/c++ in linux
I was wondering wether anyone knew a good way to learn how to use c/c++ in linux.
Quote:I was wondering wether anyone knew a good way to learn how to use c/c++ in linux.
gcc filename.c # will compile filename.c with gcc
g++ filename.cpp # will compile filename.cpp with g++
man gcc # gcc manual page
# if you have the documentation installed you can also look in /usr/share/doc/$package_name/ for additional documentation or /usr/share/doc/gcc4-4.0.0 etc your gcc version may differ
# you can also run:
# you may have to install the development tools if you do not already have them
# what version of Linux are you running?
# what kind of computer do you have (hardware specs)?
# do you already know C/C++?
Do you want to learn how to write C/C++ (from scratch) or do you know how to write C/C++ in Windows and want to learn how to write it in Linux? They are two different questions and have two different answers.
I am learning how to write C in Linux, but I have never programmed in C before. I simply bought a textbook that is used in a CS class ("C How to Program, 4th Ed. Deitel and Deitel, Prentice Hall, 2004.) as generally textbooks are better than reference books to teach oneself some topic- they have examples and problems to solve.
If you want to be able to write, compile, and execute C code in Linux, use a text editor like Kate, KWrite, or Gedit that has highlighting. It think it is a big help in seeing the different types of functions/instructions. To complie, enter something like:
gcc -o name_of_output -Wall ./name_of_source.c
and it will make an executable with whatever name you specified after -o. -Wall tells the complier to list all error and warning messages, like unused or undefined variables- things that do not cause errors severe enough to make the compiler fail. You can also use optimization flags- type in "man gcc" without the quotes to see all of the possible options you can pass to the compiler.
http://oreilly.com/ publishes some of the best computer books
You can also:
man 3 printf # brings up the manual page for the C printf function
man 3 string # string operations
man 3 stdio # stdio - standard input/output library functions
If you have the inclination and the patience you could learn how to program entirely from the man pages / other free sources of information