Introduction To C Language and Linux
Introduction To C Language and Linux
Topics to be covered
Introduction to Programming in C & Restricted Exposure to Linux - Today Data, Operators, I/O - Tomorrow Conditional Expressions, Control Flow 23rd Aug. Loops Functions for structure and Recursion Pointer and Arrays Dynamic allocation Structures and Applications, Storage Classes Pre-processor, File Handling, Math library Algorithms: searching, sorting
C Course, Programming club, Fall 2008 3
Text
Kernighan, Ritchie. Second Edition
Course website
Website (slides, important updates) http://students.iitk.ac.in/programmingclub/cour se/ Discussion page (lecture clash, doubts) http://students.iitk.ac.in/programmingclub/cour se/discuss.html
About C
GNU : GNU's Not Unix
GNU C: gcc is a standard compiler
C is non portable
Terms: Compiler (human -> machine [once]), Interpreter (instructions -> machine [each time the program is run])
My first C program!
/* thou shalt begin from somewhere*/ #include <stdio.h> // program prints hello world int main() { printf ("Hello world!\n"); return 0; }
C Course, Programming club, Fall 2008 7
More..
#include <stdio.h> // program reads and prints the same thing int main() { int number; scanf(%d, &number); printf (%d\n, number); return 0; }
C Course, Programming club, Fall 2008 8
1. Programming on Linux
Linux command line: GNU-C
Use console based editors: vi, emacs, nano Or text based editors: kwrite, gedit, kate
IDE
Eclipse * http://www.eclipse.org/cdt/downloads.php * = available on windows too.
C Course, Programming club, Fall 2008 9
Linux Familiarization
Common shell commands
Remember, commands are issued to a shell pwd, ls, dir, mkdir, cd, date, whoami touch, cp, mv, rm, chmod, cat, less, more, tail man Commands are programs (usually in /usr/bin, /bin/) Most commands take options and input
ls ls -a ls -l ls -lt ls -ltr
File
-rw-r--r-- 1 nitinm cse 3446 2008-08-14 15:16 test.c
Compiling programs
gcc <filename>.c gcc funnysingh.c o funnysingh
Running programs
./a.out ./funnysingh (executable files need to have executable permissions. $chmod +x <executable>)
C Course, Programming club, Fall 2008 12
2. C on windows
Use a text editor
install notepad++ compiler : MinGW how to install and workhttp://csjava.occ.cccd.edu/~gilberts/mingw/
IDE
Eclipse * Microsoft Visual C++ Express Edition 2008
C Course, Programming club, Fall 2008 14
15
16
17
18
19