電脳ミツバチのコンピュータ広報室

銀座の屋上菜園を耕しています。コンピュータ畑も耕します。

2005-12-15から1日間の記事一覧

②関数のポインタと構造体を使ったプログラム

少し難しいが非常に有用なプログラム。 #include<stdio.h> #include<string.h> int list(void) { printf("func list\n"); return 1; } int show(void) { printf("fanc show\n"); return 1; } int quit(void) { exit(0); } struct command{ char *com_str; int (*com_func)(void)</string.h></stdio.h>…

①メンバに文字列をコピー

メンバに文字列をコピーする。なお上で作成したヘッダファイルkouzoutai.hを使う。 #include<stdio.h> #include<string.h> #include "kouzoutai.h" int main(void){ struct p_kouzoutai copy; strcpy(copy.a,"testcopy"); printf("%s\n",copy.a); } 結果 異常終了 <|| 結果うま</string.h></stdio.h>…

①構造体の使い方

struct p_kouzoutai { char *a; char *b; char *c; } と struct a_kouzoutai { char a; char b; char c[]; } の違いは何だろうか?関数とポインタの項でやったが大きさ分のメモリを取るのが配列でアドレス分だけを取るのがポインタである。 早速見てみると、…