2008-08-01から1ヶ月間の記事一覧

構造体

例文6 #include <stdio.h> struct STUDENT{ char *name; int age; }; struct STUDENT reg(char *, int); void say(struct STUDENT *); int main(void){ struct STUDENT taro = reg("TARO", 14); say(&taro); return 0; } struct STUDENT reg(char *name, int age){ st</stdio.h>…

構造体

例文5 メンバの作成を関数で処理する。(クラスとメソッドみたい。。) #include <stdio.h> struct STUDENT{ char *name; int age; }; struct STUDENT reg(char *, int); void say(struct STUDENT); int main(void){ struct STUDENT taro; taro = reg("TARO", 14); say(</stdio.h>…

構造体

例文4 関数に構造体を引数として渡す #include <stdio.h> struct STUDENT{ char *name; int age; }; void func(struct STUDENT); int main(void){ struct STUDENT taro; taro.name = "TARO"; taro.age = 15; func(taro); return 0; } void func(struct STUDENT studen</stdio.h>…

構造体

例文3 #include <stdio.h> struct STUDENT{ char *name; int age; }; int main(void){ int index; struct STUDENT num[2]; num[0].name = "Taro"; num[0].age = 14; num[1].name = "Jiro"; num[1].age = 15; for(index=0; index<2; index++){ printf("%s -- %d\n", nu</stdio.h>…

構造体

例文2 #include <stdio.h> struct student { char *name; int age; }taro; int main(void){ taro.name = "Taro-kun"; taro.age = 15; struct student jiro; jiro.name = "Jiro-kun"; jiro.age = 14; printf("%s -- %d\n", taro.name, taro.age); printf("%s -- %d\n",</stdio.h>…

構造体

例文1 #include <stdio.h> struct { char *name; int age; }foo, bar; int main(void){ foo.name = "FOO"; foo.age = 20; bar.name = "BAR"; bar.age = 30; printf("%s -- %d\n", foo.name, foo.age); printf("%s -- %d\n", bar.name, bar.age); return 0; } C言語の</stdio.h>…

コマンドライン

argc, argvは定型として覚える。 #include <stdio.h> int main(int argc, char *argv[]){ int count = 0; while(count < argc){ printf("%d = %s\n", count++, argv[count]); } return 0; } C言語の目次</stdio.h>

関数と引数

仮引数は関数で受け取る時の変数。実引数は関数に渡す時の値 #include <stdio.h> void myfunc(char str[], int num); int main(void){ myfunc("Hoge is Hoge!!", 100); return 0; } void myfunc(char str[], int num){ printf("%s -- %d", str, num); } C言語の目次</stdio.h>

ポインタのポインタ

何度も写経して体で覚えるべし。。 #include <stdio.h> int main(void){ char str[] = "Hoge is Hoge!!"; char *p; char *(*pp); p = str; pp = &p; printf("%p\n", str); /* char型配列strの先頭アドレス */ printf("%s\n\n", str); /* 配列strの文字列(NULL文字まで</stdio.h>…

ポインタの配列

配列へのポインタではなく。。 #include <stdio.h> int main(void){ char *p[] = {"hoge", "moge", "foo", "bar"}; int i; for(i=0; i<4; i++){ printf("%s\n", p[i]); } return 0; } C言語の目次</stdio.h>

多次元配列へのポインタ

なんでキャストするのか分かりません。。 #include <stdio.h> int main(void){ int array[][3] = { {1,2,3}, {4,5,6} }; int *p; p = (int *)array; printf("%d", *(p + 3)); return 0; } C言語の目次</stdio.h>

文字列へのポインタ

これと #include <stdio.h> int main(void){ char str[] = "hogemoge"; printf("%s\n", str); return 0; } これは同じ #include <stdio.h> int main(void){ char *str = "hogemoge"; printf("%s\n", str); return 0; } C言語の目次</stdio.h></stdio.h>

ポインタ

例文 #include <stdio.h> int main(void){ char str[] = "Hoge is Hoge!"; printf("%c\n", *str); printf("%c\n", *(str + 1)); printf("%s\n", str); printf("%s\n", str + 1); return 0; } さらに。 #include <stdio.h> int main(void){ int array[] = {10,20,30}; int *p; i</stdio.h></stdio.h>…

ポインタ

例文 #include <stdio.h> int main(void){ int *p; int array[2] = {100, 200}; p = &array[0]; printf("%d--%p\n", *p, p); p++; (*p)++; printf("%d--%p\n", *p, p); return 0; } C言語の目次</stdio.h>

prototype.js分析 Enumerable

partition() 配列を条件分けする <script> Array.prototype._each = function(iterator){ for(var i=0, l=this.length; i

ポインタ

基本 include <stdio.h> int main(void){ int *p, var; var = 100; p = &var; printf("%d\n", *p); printf("%p\n", p); return 0; } C言語の目次</stdio.h>

文字列は0(ヌル文字)で終わる

これは問題ないが #include <stdio.h> int main(void){ char str[4] = "aaa"; printf("%s", str); return 0; } これはエラーとなる #include <stdio.h> int main(void){ char str[4] = "aaaa"; printf("%s", str); return 0; } *strが指し示すのは*(str + 0)なので%sが要求する</stdio.h></stdio.h>…

Emacs上でshellを使う

M-x shell Enter

C言語の目次

学習Tips gccを使う makeを使う Emacs上でshellを使う 文字列は0(ヌル文字で終わる) ポインタ 基本 例文1 例文2 文字列へのポインタ 多次元配列へのポインタ ポインタの配列 ポインタのポインタ 関数 配列を渡す ポインタを返す関数 コマンドライン argc, ar…

prototype.js分析 Enumerable

sortBy() 基準に沿ってソートする <script> Array.prototype._each = function(iterator){ for(var i=0, l=this.length; i

prototype.js分析 Enumerable

min() 要素の最小値を取得する <script> Array.prototype._each = function(iterator){ for(var i=0, l=this.length; i

prototype.js分析 Enumerable

max() 要素の最大値を取得する <script> Array.prototype._each = function(iterator){ for(var i=0, l=this.length; i

prototype.js分析 Enumerable

invoke() 各要素にメソッドを適用する <script> Array.prototype._each = function(iterator){ for(var i=0, l=this.length; i

prototype.js分析 Enumerable

pluck() 要素のプロパティを抜き出す <script> Array.prototype._each = function(iterator){ for(var i=0, l=this.length; i

prototype.js分析 Enumerable

inGroupsOf() 配列をグループ分けして、要素が足りない場合はオプションで埋める <script> Array.prototype._each = function(iterator){ for(var i=0, l=this.length; i

prototype.js分析 Enumerable

grep() 条件にマッチする要素を取り出して処理する <script> Array.prototype._each = function(iterator){ for(var i=0, l=this.length; i

prototype.js分析 Enumerable

findAll(), fileter(), select 条件にあてはまる要素を全て見つける <script> Array.prototype._each = function(iterator){ for(var i=0, l=this.length; i

prototype.js分析 Enumerable

detect() / find() 要素を見つける <script> Array.prototype._each = function(iterator){ for(var i=0, l=this.length; i

prototype.js分析 Enumerable

include() 指定された値があるか <script> Array.prototype._each = function(iterator){ for(var i=0, l=this.length; i

prototype.js分析 Enumerable

any ある要素が条件を満たしているか <script> Array.prototype._each = function(iterator){ for(var i=0, l=this.length; i