![]() |
|
|
|
|
![]() 2007 CHLUGger of the Year! Mailing List Archive Help Open Source Question of the Day Mission Directions to Meetings Contact Us Video Guest Speaker Info Acceptable Use Link To Us! Linux Hacking and the Law New! VOIP with Asterisk Assessing OSS Knoppix Ubiquitous Computing Filesystem Hierarchy Virtual Hosting Wesnoth Xbox/Linux udev Emacs Talk Notes Home Sweet ~ Top 100 CLIs Device Drivers Real Time Linux Network Considerations Part II Network Considerations Part I Amanda Presentation GNU/Linux Calculators Configuring Rio ReiserFS Linux Sound Samba notes Network time protocol C programming in Linux Boot, startup and shutdown hdparm HOWTO Ubuntu NJ LoCo New! Cherry Hill Library RUSLUG LUG in Princeton Loads of Linux Links LinuxToday.com Art of UNIX Programming More Links Contact Congress Why We Use Linux Companies Using Linux Linux in Business ![]()
![]()
![]() ![]() |
C Programming Under Linux:
Basic Concepts 1 By Carl Hein 2000. I. The C Language - * Simplest program:
main()
/* Main Routine */
* Parts of the language: - Variables: Basic Variable Types:
Arrays[ ]:
Structures:
struct player_stats
Example
usage:
- Statements: All statements must end in a semi-colon ";".
Types of statements: - Variable Assignment
- "For" loop
- "While" loop
- Subroutines:
/* Somewhere else, call as: */
Subroutines can return values,
in which case we refer to it as a function.
- Input / Output:
Screen ouput:
fptr = fopen("myfile.dat", "r");
Similarly for output, fprintf( fptr, "whatever");
II. Compiling + Running Programs - 1. Write or edit program: emacs, vi, joe, pico,
etc..
Example:
III. Debugging - If you have a problem with your program, a debugger
is often helpful.
1. Compile with -g
Pressing control-C will pause your program.
IV. Example Program /* Bubble Sort Example Program. */
/* Global Variable(s). */
/* Subroutines. */
void bubble_sort( float *list, int N )
/* The bubble sorter subroutine. */
main()
/* Main routine. */
printf("How many values
would you like to sort in the list ? ");
V. More Hints -
* For help at any time, use the on-line manual: man Example: man scanf * Math functions, such as sin, cos, tan, sqrt, log, exp, random,
etc., require that you
#include <math.h>
* If you forget the -o executable_name on the compile
line, then C compilers
* All arrays start at zero (0).
* Other good resources: C-Programming, K&R (Brian Kernighan,
Dennis Ritchie)
|