毛のはえたようなもの

インターネット的なものをつらつらとかきつらねる。

C言語

文字列のエンコード・デコード

あと知り合いMがを16進数文字列を解読可能に直すプログラムを書いたのを見せてくれました。実験を選択した人にはずいぶん参考になる気がしたので掲載します。了解はとりました。はやさんによれば、「%encode」というのが当たりらしい。 初心者てググる言葉を…

ネットワークプログラミング課題2

ソケットを開いて受信した相手のデータを表示し続けるだけのプログラム。 ソース汚い&C言語は正規表現使えないらしいのでC++に乗り換えようかと思っているところ。 #include <stdio.h> #include <string.h> #include <ctype.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> #define PORT 5555 void er</netdb.h></netinet/in.h></sys/socket.h></ctype.h></string.h></stdio.h>…

ネットワークプログラミング1

socketを使おう!の巻。説明は面倒くさいのでしないというか、私もよくわかってない(o^▽^o) #include <stdio.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> #define PORT 5555 void err_check(int res, char function_name[]); int main(int argc , char* argv[]){ int new_socke</netdb.h></netinet/in.h></sys/socket.h></stdio.h>…

範囲に収まる数字の数(c言語の場合)

#include <stdio.h> #include <math.h> int compare_int(const int *a,const int *b){ return *b- *a; } int main(){ int i = 0; int j = 0; int k = 0; char buf[1000]; int num[1000]; int flag=0; int w; int max=0; int target=0; while(fgets(buf, 1000,stdin) != NULL){</math.h></stdio.h>…

相異なる文の種類の数(c言語の場合)

#include <stdio.h> #include <math.h> #include <string.h> int cmp(const char *a,const char *b){ return strcmp(b,a); } int main(void){ char buf[1000]; FILE *stream; char string[10001][70]; int i = 0; int j = 0; int chohuku =0; while(fgets(buf, 1000,stdin) != NULL){ st</string.h></math.h></stdio.h>…

重複する数字を表示(c言語の場合)

#include <stdio.h> #include <math.h> // 昇順に並べる int compare_int(const int *a,const int *b){ return *b- *a; } int main(){ int i = 0; int j = 0; char buf[1000]; int num[1000]; // ファイルからの入力 while(fgets(buf, 1000,stdin) != NULL){ if(atoi(buf) == </math.h></stdio.h>…

k番目に大きい数(cの場合)

#include <stdio.h> #include <string.h> int compare_int(const int *a,const int *b){ return *b- *a; } int main(){ int num[1000]; char string[1000]; int n ,k ,x; int i=0; fgets(string, 1000,stdin); sscanf(string,"%d %d",&n,&k); while(fgets(string, 1000,stdin) !</string.h></stdio.h>…

右側折り返し(cの場合)

#include <stdio.h> int main(void){ int num=0; char word; FILE *stream; int maxlength=71; stream = fopen("../data_c.txt","r"); while((word = getc(stream)) != EOF){ if(word == '\n'){ num=0; }else if(num > maxlength){ printf("\n"); num=0; }else{ num++</stdio.h>…

精度を要する割り算(cの場合)

#include <stdio.h> int main(){ char string[10000]; double a, b; while(fgets(string, 10000,stdin) != NULL){ sscanf(string,"%d %d",&a,&b); if(a==0 && b==0){ break; }else{ printf("%0.10f\n",a/b); } } return 0; }</stdio.h>

標準入力から一行づつ読み込み最大値を表示(Cの場合)

#include <stdio.h> #include <string.h> int main(){ int max; char buf[1000]; char* num; int flag = 0; while(fgets(buf, 1000,stdin) != NULL){ num = strtok(buf," \n"); while(num != NULL){ if(flag == 0 || max < atoi(num)){ flag = 1; max = atoi(num); } num =strto</string.h></stdio.h>…