http://coder.aqualuna.me/2011/12/eclipse-cc.html
https://docs.google.com/document/d/1sgFvCY-2j1t8rc4EEWrMWPfK9zxMuVLFlbqjThQ3Y8g/edit?usp=sharing
安裝cygwin
http://www.cygwin.com
x86_64.exe
執行
照Default 下一步
選
Install from Internet
直接使用預設路徑C:\cygwin64
安裝所需的各式種類的程式會先被儲存到儲存目錄中,在這邊我們設定為C:\cygwin64
選
選擇Direct Connection
選擇程式來源網站 Choose A Download Site
選近一點的日本網站
在
Devel Default
選gcc-core及gcc-g++把前有無cygwin32皆加入
cygwin32-gcc-core:GCC for Cygwin 32bit toolchain (C, OpenMP)
cygwin32-gcc-g++:GCC for Cygwin 32bit toolchain (C++)
gcc-core:GNU Compiler Collection(C, OpenMP)
gcc-g++:GNU Compiler Collection (C++)
安裝gdb
gdb:The GNU Debugger
安裝make
make:The GNU version of the 'make' utility
安裝lex
flex:A fast lexcial analyzer generator
安裝bison
bison:GNU yacc-compatible parser generator
在
Utils Default
安裝util-linux
util-linux Random collection
下一步
完成
點開 Windows 的選單, 在程式搜尋地方輸入 systempropertiesadvanced, 然後按下 Enter Key.
進階/環境變數/系統變數/Path/編輯/
;%ANDROID_TOOL%\bin;c:\cygwin64\bin
安裝telnet(下載puttytel)
http://www.chiark.greenend.org.uk/
設Path
控制台\系統及安全性\系統\進階系統設定\進階\環境變數\系統變數\PATH反白\編輯\最後處加上;c:\cygwin64\bin\確定
安裝eclipse
https://www.eclipse.org/downloads
選
Eclipse IDE for C/C++ Developers
Help/About Eclipse
確認安裝
File/New/C Project
Project Name/Hello World
Project type/Hello World ANSI C Project
Toolchain/Cygwin GCC
Project/Build Project
Project/Run
下載cppcheck.sourceforge.net
Browser/Folder name/c:\cppcheck/OK
下載cppcheclipse
Run Eclipse
Eclipse/windows/Preference/General/Editors/Text Editors/Show line numbers打勾
Eclipse/windows/Preference/C/C++/Debug/Source Lookup Path/Add/Path Mapping/OK/Add/Name: New Mapping/Compilation Path:/cygdrive/c /Local file system path: C:\
1. Content Assist ⇒ alt + /
2. Auto comment/ uncomment ⇒ ctrl + /
3. auto format ⇒ ctrl + shift + f
4. select all ⇒ ctrl +a
寫程式
Eclipse/File/New/C Project/Project Name:Day1_1/Project Type:Empty/Toolchains:Cygwin GCC/Finish
Project Explorer/Day1_1/反白/File/New/Source File/Source folder:Day1_1/Source File:main.c/Finish
設Toolchains
Windows/Preference//New C/C++ Project Wizard/Toolchains/反白Cygwin GCC/按Make toolchain(s) preferred鍵/反白Cygwin GCC前出現三角形/按OK
右key/Run As/
~~~~~~~~~~~~~~~~~~~~
#include
#define MAXLINE 1000
// function declaration
int _getline(char line[], int max);
int strindex(char source[], char searchfor[]);
char pattern[]="ould";
~~~~~~~~~~~~~~~~~~~~
int main(int argc, char **argv) {
printf("input something into console\n");
fflush(stdout);
char line[MAXLINE];
int found = 0;
while (_getline(line, MAXLINE) > 0) {
if (strindex(line, pattern) > 0) {
fflush(stdout);
found++;
}
return found;
}
return 0;
}
~~~~~~~~~~~~~~~~~~
// function definition
int _getline(char line[], int limit) {
int c, i;
i = 0;
while (--limit > 0 && (c = getchar()) != EOF && c != '\n') {
line[i++] = c;
}
if (c == '\n') {
line[i++] = c;
}
line[i]='\0';
printf("get line count=%d\n",i);
fflush(stdout);
return i;
}
~~~~~~~~~~~~~~~~~~~~
int strindex(char source[], char searchfor[]) {
int i, j, k;
for (i = 0; source[i] != '\0'; i++) {
for (j = i, k = 0; searchfor[k] != '\0' && source[j] == searchfor[k];
j++, k++) {
}
if (k>0 && searchfor[k]=='\0') {
printf("found key at %d\n",i);
return i;
}
}
return -1;
}
~~~~~~~~~~~~~~~~~~~~~~~
#include
void printd(int n) {
if (n<0) {
putchar('-');
n=-n;
}
if (n/10) {
printd(n/10);
}
putchar(n%10 + '0');
fflush(stdout);
}
int main(int argc, char **argv) {
int x =123456;
printd(x);
}
~~~~~~~~~~~~~~~~~~~~~
#include
int foo1 = 0;
int foo2 = 5;
int main(int argc, char **argv) {
int bar1 = 3;
int bar2 = 99;
printf("foo1 address=%p, foo2 address=%p\n",&foo1, &foo2);
printf("bar1 address=%p, bar2 address=%p\n",&bar1, &bar2);
return 0;
}
~~~~~~~~~~~~~~~~~~~~~~~`
#include
void moveSouthWest(int pointX, int pointY) {
pointX--;
pointY--;
}
int main(int argc, char **argv) {
int locationX=0;
int locationY=0;
moveSouthWest(locationX,locationY );
printf("after move, address=(%d,%d)",locationX, locationY);
}
pp.103, &, *, *
void moveSouthEast(int* pointX, int* pointY) {
(*pointX)++;
(*pointY)--;
}
~~~~~~~~~~~~~`
#include
int main(int argc, char **argv) {
int p=4;
float q = 5.7;
long r = 3333333;
double s = 1.23456789;
int *pointP = &p;
float *pointQ = &q;
long *pointR = &r;
double *pointS = &s;
printf("size p=%lu, pointP=%lu\n",sizeof(p),sizeof(pointP));
printf("size q=%lu, pointQ=%lu\n",sizeof(q),sizeof(pointQ));
printf("size r=%lu, pointR=%lu\n",sizeof(r),sizeof(pointR));
printf("size s=%lu, pointS=%lu\n",sizeof(s),sizeof(pointS));
return 0;
}