0. install compiler and associate environment.
sudo apt-get install build-essential
or install with CD(without internet):
sudo apt-cdrom add
sudo aptitude update
sudo aptitude install build-essential
gcc -v
1. The printf("Content-type:text/plain\n\n"); is mandatory for cgi program, otherwise the first part of content won't display in browser.
2. int main(int argc, char *argv[], char *env[]) {}
argc ##the count of arguments
argv[] ## argument array
env[] ## environment variables array
3. #define STRINGSIZE 256
not #DEFINE, should be lowercase in Ubuntu cc.
4. char=1 byte, int=4 bytes, float=4 bytes
Each data type has a specified size and the sizeof() library function will return this as an integer.
5. %c ## character
%d ## integer
%s ## string
%f ## floating pointer number
6. compile a set of c file
create a file named Makefile, and write as below:
------------------------------
#Makefile
all:chap1
chap1:1-1 1-2 1-3 1-4
1-1:
cc -o hello chapter1_1.c
1-2:
cc -o args chapter1_2.c
1-3:
cc -o args.cgi chapter1_3.c
1-4:
cc -o env.cgi chapter1_4.c
---------------------------------
note: the tab after each make target is vital to the syntax of make.
7. string.h
strtok
atoi
strcpy
getenv
8. sprintf
char SQL[1024] = "";
sprintf(SQL, "insert into CIL values('%s', '%s')", argv[1], argv[2]);
9. putchar / getchar
10. printf / scanf
%[m/-m]d
%ld ## long int
%o ## octal
%x ## hex
%u ## unsigned
%m.ns ## capture the left n characters, hold m columns, align right
%.ns ## m=n
%m.nf ## n is decimal
%m.ne ## index
11. real number (float, double)
1.0f ## float
compile:
--------------------------------
1. <math.h> --- -lm
2. <mysql.h> --- -lmysqlclient
FILE
--------------------------------
fopen:
File *fp = fopen("filename", "openType");
exception: NULL(NULL == 0)
openType:
r ## file must exsit
w ## if file exsits, delete it first, and create a new one
a ## file must exsit
rb
wb
ab
r+ ## file must exsit
w+
a+ ## file must exsit
rb+
wb+
ab+
if ((fp=fopen("filename", "r")) == NULL) {
printf("error open file.");
exit(0);
}
note: exit(0); will close file, and halt process.
fclose:
fclose(fp);
success: return 0
failure: return EOF(-1)
fputc/fgetc/putc/getc/feof:
fputc(ch, fp);
success: return ch
failure: return EOF(-1)
note: #define putchar(ch) fputc(ch, stdout)
-----
fgetc(fp);
success: return ch
failure: return EOF(-1)
-----
feof(fp);
1 : end of file
0 : not yet
-----
#define putc(ch, fp) fputc(ch, fp)
#define getc(fp) fgetc(fp)
-----
fread/fwrite:
fread(buffer, size, count, fp);
fwrite(buffer, size, count, fp);
buffer - pointer of location
size - read/write how many bytes one time
count - how many times
fp - FILE pointer
-----
fprintf/fscanf:
fprintf(fp, "format", i, j, k, ...);
fscanf(fp, "format", &i, &j, &k,...);
-----
putw/getw: (w = 2 bytes)
putw(10, fp);
-----
fputs/fgets:
fputs("China", fp); ## the first argument can be literal, char[], char *
success: return 0
failure: return EOF(-1)
fgets(str, n, fp);
str - string array
n - array size, (n-1)char + '\0'
fp - FILE pointer
return first address of string array.
rewind/fseek/ftell:
rewind(fp);
fseek(fp, offset, direction);
direction - 0 ## header
- 1 ## current
- 2 ## end
int i = ftell(fp); ## the current offset of pointer
success: return i
failure: -1L
ferror/clearerr:
ferror(fp);
no error: return 0
has error: return non 0
clearerr(fp); ## set the ferror=0
Struct/Union
--------------------------------
.has highest priority
Bit Operation
--------------------------------
&:
1. reset to 0;
2. obtain specified bits
3. only remain specified bits
|:
1. set specified bits to 1
^:
1. swap two int without "middle temp variable"
2. reverse the specified bits
3. a ^ 0 = a
~:
1. 1->0, 0->1 increase migration capability
<<:
1. append 0 in the right side
>>:
1. logical >>: append 0 in the left side
2. arithmetial >>: append 1 in the left side if it's a negative
append 0 if it's positive
分享到:
相关推荐
C Clearly Programming C in Linux and on Raspberry Pi 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
C Clearly Programming C in Linux and on Raspberry Pi 英文mobi 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
C Clearly Programming C in Linux and on Raspberry Pi 英文azw3 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
C_Programming_in_Linux.pdf C_Programming_in_Linux.pdf C_Programming_in_Linux.pdf
this book is meant to further knowledge by detailing how dynamic data structures are used in practice, using programming exercises and programming projects on such topics as C structures, pointers, ...
This guide attempts to introduce the 'C' Programming Language to the novice programmer, using Linux as the host environment. This means you can learn C on a Raspberry Pi or you can use a distribution ...
根据提供的信息,我们可以总结出以下关于《Linux下的C语言编程》的相关知识点: ### 一、简介 本书由David Haskins编写,详细介绍了在Linux环境下进行C语言编程的基础与高级技巧。作者通过丰富的实例和深入浅出的...
在深入探讨《C Programming in Linux》一书的内容之前,我们首先需要理解几个核心概念:C语言、Linux系统以及它们在编程领域中的应用。C语言是一种结构化的编程语言,以其高效性和灵活性著称,广泛应用于系统编程、...
根据提供的文件信息,我们可以总结出以下关键知识点,这些知识点主要围绕着在Linux环境下进行C语言编程的基础内容展开。 ### C语言编程基础 #### Hello World程序 - **介绍**:通常作为学习任何一种新编程语言的第...
因此,我将从【标题】和【描述】中提供的信息,即《C_Programming_in_Linux》介绍Linux下C语言的手册来构建知识点。 Linux下C语言编程的知识点主要涉及以下方面: 1. Linux环境基础:了解Linux操作系统的基本知识...
《David Haskins - C Programming in Linux》是2009年出版的一本关于Linux环境下C语言编程的书籍。这本书详细介绍了如何在Linux操作系统中进行C语言编程,涵盖了从基本概念到高级技术的广泛主题。以下是一些核心知识...
《Linux下C语言编程》是一本专为在Linux操作系统中使用C语言进行程序开发而设计的教程。本书旨在帮助初学者以及有一定经验的程序员更好地理解和掌握C语言在Linux环境下的应用,尤其关注如何利用C语言编写CGI(Common...
在IT领域,Linux C编程是基础且至关重要的技能,它结合了C语言的强大与Linux操作系统的灵活性。Linux作为开源操作系统,提供了丰富的系统调用和工具,而C语言则是编写底层软件和系统级程序的首选语言。这篇内容将...
本书名为《C语言在Linux下的编程》,作者为David Haskins,是一本专注于在Linux操作系统环境下进行C语言编程的教程书籍。该书通俗易懂,面向学习者,并且书中有描述称它是值得学习的好书。根据提供的部分目录和内容...
本书《Shell Programming in Unix Linux and OS X (4th)》是关于Unix、Linux和OS X操作系统下的Shell编程的专业书籍,由Stephen G. Kochan和Patrick Wood编写。本书是第四版,是为需要掌握Shell脚本编程技术的程序员...
Beginning Linux Programming, Fourth Edition continues its unique approach to teaching UNIX programming in a simple and structured way on the Linux platform. Through the use of detailed and realistic ...