2008-08-31から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>