C言語

高い本ですが。。

ピアソン本は概して高いけれど、それに値する内容が詰まっている。 にしても新高円寺で介護をしていた頃はすぐそばの桐原書店がピアソンの日本代理店?だとは思ってもいなかった。聞いたことのない書店だけれど割と立派なビルだなとぐらいにしか。。詳解TCP/…

リトルエンディアンとビッグエンディアン

ネットワークバイトオーダーを理解する必要にかられてなんとなく通り過ぎていた所を復習 ブログへ

psコマンドのソースを読む。 なかなかお勉強になります。その他のソースもたくさん読みたい。

openとchmod

apropos chmodコマンドで数パターンのmanコマンドがあるのが確認できる。 man 2 chmodでc言語で使う関数の方が確認できる。 #include <stdio.h> #include <fcntl.h> #include <sys/stat.h> int main(){ int fp; fp = open ("foobar.txt", O_WRONLY | O_CREAT); if(fp != -1) chmod("foobar</sys/stat.h></fcntl.h></stdio.h>…

openとread

#include <stdio.h> #include <fcntl.h> int main(){ int fp; char c[20]; fp = open("./test.txt", O_RDONLY); read(fp, c, 20); printf("%s", c); return 0; } /* test.txtは以下 0123456789 0123456789 ちなみに2行目の8まで表示される。*/ C言語の目次</fcntl.h></stdio.h>

fgetcとfputc

#include <stdio.h> int main(){ FILE *fp; char c; fp = fopen("test.txt", "r"); while( (c = fgetc(fp)) != EOF){ /*printf("%c", c);*/ fputc(c, stdout); } fclose(fp); return 0; } C言語の目次</stdio.h>

fgetsとfputs

備忘録、と。 #include <stdio.h> int main(){ FILE *fp; char str[256]; fp = fopen("./test.txt", "r"); while(fgets(str, 256, fp) != NULL){ /* printf("%s", str); */ fputs(str, stdout); } return 0; } C言語の目次</stdio.h>

getsとputs

getsは問題のある関数で使うべきではない、とされている。コンパイルすると警告が出る。実行はできるが。バッファサイズを指定できないのが問題か。 #include <stdio.h> int main(){ char str[10]; gets(str); puts(str); return 0; } C言語の目次</stdio.h>

getcとputc, getcharとputchar

こんがらがったので備忘録 #include <stdio.h> int main(){ char c; c = getc(stdin); putc(c, stdout); return 0; } #include <stdio.h> int main(){ char c; c = getchar(); putchar(c); return 0; } C言語の目次</stdio.h></stdio.h>

makefileをつくる

備忘録。超初心者w test: foo.c gcc foo.c -o rs.exe C言語の目次へ

「Unix/Linuxプログラミング 理論と実践」を再度やりはじめる。外注案件、CCNP受験勉強とやること盛りだくさんだけれども。 禁酒したことでちょっと見えてきたことがあって、それは毎日集中するようになると何を優先的に片付けていけばいいのかがハッキリと…

ファイルまわり

変数宣言した時に*str="hogehoge"とするのは便利だけど、宣言する時だけしかできないのかな。。 以下、EOFの時はfgets()がNULLなのでwhile文が実行されず、「Complete」の部分は出力されません 追記:strcpyとmallocを使えば良いと気づきました。 #include <stdio.h> </stdio.h>…

ポインタを返す関数

strcatの自作 #include <stdio.h> #include <string.h> char *mystrcat(char *, char *); int main(void){ char str1[16] = "hoge"; char *str2 = "moge"; printf("%s\n", mystrcat(str1, str2)); return 0; } char *mystrcat(char *a, char *b){ char *p; int n = 0; p = a + s</string.h></stdio.h>…

構造体

メンバに同じ型へのポインタを持つ #include <stdio.h> typedef struct STUDENT{ char *name; int age; struct STUDENT *next; }DATA; int main(void){ DATA taro = {"TARO", 16}; DATA jiro = {"JIRO", 15}; DATA hana = {"HANA", 14}; DATA *p; taro.next = &jiro; </stdio.h>…

構造体

typedefを使う #include <stdio.h> typedef struct STUDENT{ char *name; int age; }MYDATA; void SirYesSir(MYDATA *); int main(void){ MYDATA taro; MYDATA *p; p = &taro; taro.name = "TARO"; taro.age = 22; printf("%s - %d\n", taro.name, taro.age); SirYesS</stdio.h>…

構造体

例文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>

ポインタ

基本 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>