ほかんじょ
http://w.atwiki.jp/chuo713/
ほかんじょ
ja
2010-07-14T18:35:09+09:00
1279100109
-
システムプログラム02-ver02_server
https://w.atwiki.jp/chuo713/pages/46.html
/* ポート番号9000を使用する */
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#define NSTRS 1 /* 文字列の個数 */
#define STRMAX 60 /* 文字列長さ */
char *strs[NSTRS];
char *root;
extern int errno;
int main(int ac, char *av[]){
char c;
FILE *fp;
int fromlen;
char hostname[64];
struct hostent *hp;
register int i,s,ns;
struct sockaddr_in sin, fsin;
printf(">> server run\n");
gethostname(hostname,sizeof(hostname));
if((hp=gethostbyname(hostname))==NULL){
fprintf(stderr,"%s: unknown host.\n", hostname);
exit(1);
}
fprintf(stderr,">> hosting : %s\n", hostname);
if((s=socket(AF_INET,SOCK_STREAM,0))<0){
perror("clisent: socket");
exit(1);
}
sin.sin_family=AF_INET;
sin.sin_port=htons(9000);
sin.sin_addr.s_addr=htonl(INADDR_ANY);
if(bind(s,(struct sockaddr*)&sin,sizeof(sin))<0){
perror("server: bind");
exi
2010-07-14T18:35:09+09:00
1279100109
-
システムプログラム02-ver02_client
https://w.atwiki.jp/chuo713/pages/45.html
/* ポート番号9000を使用する */
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#define NSTRS 1 /* 文字列の個数 */
#define STRMAX 60 /* 文字列長さ */
char *strs[NSTRS];
extern int errono;
void input_strs(){
int i;
char e[]="\n";
for(i=0;i<NSTRS;i++){
printf("str[%d]:",i);
strs[i]=malloc(STRMAX);
gets(strs[i]);
strcat(strs[i],e);
}
}
int main(int ac, char *av[]){
char c;
FILE *fp;
char hostname[64];
register int i,s;
struct hostent *hp;
struct sockaddr_in sin;
printf(">> client run\n");
/* まずホストネームを取得 */
printf("__connect server name ? :");
gets(hostname);
if((hp=gethostbyname(hostname))==NULL){
fprintf(stderr,"%s: unknown host.\n", hostname);
exit(1);
}
if((s=socket(AF_INET,SOCK_STREAM,0))<0){
perror("clisent: socket");
exit(1);
}
sin.sin_family=AF_INET;
sin.sin_port=htons(9000);
bcopy(hp
2010-07-14T18:33:39+09:00
1279100019
-
システムプログラム02-ver01_server
https://w.atwiki.jp/chuo713/pages/44.html
/*
* ポート番号9000を使用する
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#define NSTRS 3 /* 文字列の個数 */
#define STRMAX 10
char *strs[NSTRS];
char *tmp;
char *root;
extern int errno;
int main(int ac, char *av[]){
char c;
FILE *fp;
FILE *tfp;
int fromlen;
char hostname[64];
struct hostent *hp;
register int i,s,ns;
struct sockaddr_in sin, fsin;
printf(">> server run\n");
/*
* 何はともあれ、ホストネームを取得
*/
gethostname(hostname,sizeof(hostname));
/*
* ホストネームのネットワーク番号を取得
*/
if((hp=gethostbyname(hostname))==NULL){
fprintf(stderr,"%s: unknown host.\n", hostname);
exit(1);
}
fprintf(stderr,">> hosting : %s\n", hostname);
/*
* ソケットを取得、このソケットはインターネットドメインで、ストリーム型
*/
if((s=socket(AF_INET,SOCK_STREAM,0))<0){
perror("clisent: socket");
exit(1);
}
/* アドレス構造体を作成する。ここではポート番号 9000を
* 使用する
2010-07-13T21:00:12+09:00
1279022412
-
システムプログラム02-ver01_client
https://w.atwiki.jp/chuo713/pages/43.html
/* pp.215-217 */
/* connects to the local host at port 1234 */
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#define NSTRS 3 /* 文字列の個数 */
#define STRMAX 10
/*
* サーバに送る文字列を作成する
*/
char *strs[NSTRS];
extern int errono;
void input_strs(){
int i;
char e[]="\n";
for(i=0;i<NSTRS;i++){
printf("str[%d]:",i);
strs[i]=malloc(STRMAX);
gets(strs[i]);
strcat(strs[i],e);
}
}
int main(int ac, char *av[]){
char c;
FILE *fp;
char hostname[64];
register int i,s;
struct hostent *hp;
struct sockaddr_in sin;
printf(">> client run\n");
/*
* まずホストネームを取得
*/
printf("__connect server name ? :");
gets(hostname);
input_strs();
/* gethostname(hostname,sizeof(hostname));
*/
/*
* つぎに、ホストのネットワークアドレスを取得
*/
if((hp=gethostbyname(hostname))==NULL){
fprintf(stderr,"%s: unknown host.\n", hostname);
2010-07-13T20:59:29+09:00
1279022369
-
システムプログラム02-ver00_server
https://w.atwiki.jp/chuo713/pages/42.html
/*
* ポート番号9000を使用する
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#define NSTRS 3 /* 文字列の個数 */
/*
* クライアントに送る文字列
*/
char *strs[NSTRS] = {
"This is the first string from the server.\n",
"This is the second string from the server.\n",
"This is the third string from the server.\n"
};
extern int errno;
int main(int ac, char *av[]){
char c;
FILE *fp;
int fromlen;
char hostname[64];
struct hostent *hp;
register int i,s,ns;
struct sockaddr_in sin, fsin;
/*
* 何はともあれ、ホストネームを取得
*/
gethostname(hostname,sizeof(hostname));
/*
* ホストネームのネットワーク番号を取得
*/
if((hp=gethostbyname(hostname))==NULL){
fprintf(stderr,"%s: unknown host.\n", hostname);
exit(1);
}
/*
* ソケットを取得、このソケットはインターネットドメインで、ストリーム型
*/
if((s=socket(AF_INET,SOCK_STREAM,0))<0){
perror("clisent: socket");
exit(1);
}
/
2010-07-13T20:58:17+09:00
1279022297
-
システムプログラム02-ver00_client
https://w.atwiki.jp/chuo713/pages/41.html
/* pp.215-217 */
/* connects to the local host at port 1234 */
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#define NSTRS 3 /* 文字列の個数 */
/*
* サーバに送る文字列
*/
char *strs[NSTRS] = {
"This is the first string from the client.\n",
"This is the second string from the client.\n",
"This is the third string from the client.\n"
};
extern int errno;
int main(int ac, char *av[]){
char c;
FILE *fp;
char hostname[64];
register int i,s;
struct hostent *hp;
struct sockaddr_in sin;
/*
* まずホストネームを取得
*/
gethostname(hostname,sizeof(hostname));
/*
* つぎに、ホストのネットワークアドレスを取得
*/
if((hp=gethostbyname(hostname))==NULL){
fprintf(stderr,"%s: unknown host.\n", hostname);
exit(1);
}
/*
* 通信用ソケットを取得、このソケットはインターネット
* ドメインで、ストリーム型(接続型)である
*/
if((s=socket(AF_INET,SOCK_STREAM,0))<0){
perror("clisent: socket");
2010-07-13T20:57:02+09:00
1279022222
-
システム工学(ファジーなんちゃら)-20100629
https://w.atwiki.jp/chuo713/pages/40.html
<p>#include <stdio.h><br />
#include <stdlib.h></p>
<p>double f(double c){<br />
if((0<=c)&&(c<=50)){<br />
return 1.0/50*c;}<br />
else if(50<c){<br />
return 1.0;}<br />
return -1.0;<br />
}<br />
double g(double c){<br />
if((0<=c)&&(c<=20)){<br />
return 1.0;}<br />
else if((20<c)&&(c<=40)){<br />
return -1.0/20*c+2.0;}<br />
else if(40<c){<br />
return 0.0;}<br />
return -1.0;<br />
}<br />
double p(double x){<br />
if((0<=x)&&(x<=20)){<br />
return 0.0;}<br />
else if((20<x)&&(x<=40)){<br />
return 1.0/20*x-1.0;}<br />
else if((40<x)&&(x<=60)){<br />
return -1.0/20*x+3.0;}<br />
else if(60<x){<br />
return 0.0;}<br />
return -1.0;<br />
}<br />
double q(double x){<br />
if((0<=x)&&(x<=40)){<br />
return 0.0;}<br />
else if((40<x)&&(x<=60)){<br />
return 1.0/20*x-2.0;}<br />
else if((60<x)&&(x<=80))
2010-06-29T05:02:32+09:00
1277755352
-
個人特定問題
https://w.atwiki.jp/chuo713/pages/39.html
<p>#include <stdio.h><br /><br />
#define M 11<br />
#define N 16<br /><br />
int data[M][N];<br /><br />
void input(){<br />
int i,j;char c;<br />
for(i=0;i<M;i++){<br />
for(j=0;j<N;j++){<br />
c=getchar();<br />
/* printf("input=%d\n",c);*/<br />
if(c!=10){data[i][j]=c-48;}<br />
if(c==10){j--;}<br />
}<br />
}<br />
}<br /><br />
void q_abi(int use[M],int see[N],double abi[M]){<br />
int i,j,n;<br />
for(i=0;i<M;i++){<br />
abi[i]=0;n=0;<br />
for(j=0;j<N;j++){<br />
if((use[i]==1)&&(see[j]==1)){<br />
/*
printf("data[%d][%d]=%d,abi[%d]=%lf\n",i,j,data[i][j],i,abi[i]);<br />
*/ n++;<br />
abi[i]=abi[i]+data[i][j];<br />
}<br />
}<br />
/* printf("abi[%d]=%.2lf n=%d abi/n=%lf |p|=%lf\n",
i,abi[i],n,abi[i]/n,(abi[i]/n-0.5)*(abi[i]/n-0.5));<br />
*/<br />
if(n>0){<br
2010-06-09T16:28:29+09:00
1276068509
-
システムプログラム01-ver01
https://w.atwiki.jp/chuo713/pages/38.html
<p>#include <stdio.h><br />
#include <stdlib.h><br />
#include <ctype.h><br />
#include <string.h><br /><br />
#define LIST 00<br />
#define SYMBOL 01<br /><br />
typedef struct ptr{<br />
int tag;<br />
union{<br />
struct cell{<br />
struct ptr*car;<br />
struct ptr*cdr;<br />
}cell;<br />
struct symbol{<br />
char *pname;<br />
struct ptr*plist;<br />
}symbol;<br />
long int intv;<br />
}atr;<br />
}*Ptr;<br /><br />
Ptr oblist=NULL;<br />
Ptr true_pointer;<br />
Ptr nil_pointer;<br />
Ptr dot_pointer;<br />
Ptr rpar_pointer;<br />
Ptr quote_pointer;<br />
char* pname(Ptr x) {return x->atr.symbol.pname;}<br /><br />
Ptr symbolp(Ptr x)<br />
{ if((x->tag)==SYMBOL)return true_pointer;<br />
else return nil_pointer;<br />
}<br /><br />
Ptr CAR(Ptr x) {return x->atr.cell.car;}<br />
Ptr CDR(Ptr x) {return x->atr.cell.cdr;}<br />
Ptr print_expr(Ptr x)<br />
{ if(symbolp(x)==
2010-05-10T15:24:31+09:00
1273472671
-
システムプログラム01-ver00
https://w.atwiki.jp/chuo713/pages/37.html
<p>#include <stdio.h><br />
#include <stdlib.h><br />
#include <ctype.h><br />
#include <string.h><br /><br />
#define LIST 00<br />
#define SYMBOL 01<br /><br />
typedef struct ptr{<br />
int tag;<br />
union{<br />
struct cell{<br />
struct ptr*car;<br />
struct ptr*cdr;<br />
}cell;<br />
struct symbol{<br />
char *pname;<br />
struct ptr*plist;<br />
}symbol;<br />
long int intv;<br />
}atr;<br />
}*Ptr;<br /><br />
Ptr oblist=NULL;<br />
Ptr true_pointer;<br />
Ptr nil_pointer;<br />
Ptr dot_pointer;<br />
Ptr rpar_pointer;<br />
char* pname(Ptr x) {return x->atr.symbol.pname;}<br /><br />
Ptr symbolp(Ptr x)<br />
{ if((x->tag)==SYMBOL)return true_pointer;<br />
else return nil_pointer;<br />
}<br /><br />
Ptr CAR(Ptr x) {return x->atr.cell.car;}<br />
Ptr CDR(Ptr x) {return x->atr.cell.cdr;}<br />
Ptr print_expr(Ptr x)<br />
{if(symbolp(x)==true_pointer){<br />
fprintf(stdout, "%s",pname(x));<br />
}else{<br />
fprintf(stdout, "(");<br />
prin
2010-04-28T18:16:08+09:00
1272446168