2015-08-30から1日間の記事一覧

C言語でネットワークプログラミング

まずはソケットにファイルディスクリプタを代入する。 socketはシステムコールです。 socketシステムコール TCPまたはUDP通信を行う場合に、OSにソケットの作成を依頼します。 #include<sys/types.h> #include<sys/socket.h> int socket(int domain, int…

perlの配列の(1..1000)

1番から1000番までを表示する方法。 Linuxではseqがあるからいいけど。 まぁperlも便利な方法がありますね。 #!/usr/bin/perl use strict;use warnings; my @box = (1..1000); foreach (@box){ print "$_\n";}~~

perlの配列のqw

qwを使用した場合は、 文字列時のシングルコーテーションやダブルコーテーション、または「カンマ」などを 文字のセパレート使用するものを省略できます。 #!/usr/bin/perl use strict;use warnings; my @box = qw(yoshida ando nakajima); foreach (@box) {…

perlの文字列の場合の配列

#!/usr/bin/perl use strict;use warnings; my @box = ("kengo","manabu","taku","takeshi","hiroyuki"); foreach(@box){ print "$_\n";}~

foreachについて

foreachについて。どうですか。 配列を展開するときなんかは便利ですね。 ちなみに文字列を配列にリスト代入する方法は異なります。C言語みたい。 #!/usr/bin/perl use strict;use warnings; my @box = (1,2,3); foreach (@box) { print $_;}~

perlで大事なもの

chomp・・・文字列比較の際に、改行コードを除く。perlで文字列検索するときは必須。意外と忘れる。 if文・・・・開始の{と終了の}が必要です。 出力演算にはprintを使用しましょう。!!

はい。perlです。STDINを使った場合について

まずはperl復習。だいぶ忘れている。。 [root@gochamaze Perl]# cat stdin.pl#!/usr/bin/perl use strict;use warnings; print "What are your name ?\n"; my $box = <STDIN>; chomp($box); if ($box eq "yoshida"){ print "yoshida";}else { print "No yoshida";}</stdin>

/proc/statの計算式を入れてみた。(ただしこれは計算式が間違っています)。後日修正予定。。。

[root@gochamaze C]# cat cpuinfo3.c#include <stdio.h>#include <string.h>#include <stdlib.h> typedef struct cpuinfo { char name[50]; int count1; int count2; int count3; int count4; int count5; int count6; int count7; int count8; int count9;} cpu; int main(void){ FILE *r</stdlib.h></string.h></stdio.h>…

C言語で/proc/statの値をfscanfしてみる

いつもfsanfして間違えるところは、fscanfをint型を受け取るとき &を付け忘れること。。。 気を付けましょう [root@gochamaze C]# cat cpuinfo3.c#include <stdio.h>#include <string.h>#include <stdlib.h> typedef struct cpuinfo { char name[50]; int count1; int count2; int count3;</stdlib.h></string.h></stdio.h>…

Ver検索のバージョンアップ版

指定したディレクトリ内のファイルの中身を検索し、 Verという文字がファイルにあれば、その一番したのVerを出す。 [root@gochamaze C]# cat directory.c#include <stdio.h>#include <dirent.h>#include <string.h> #define BUF 256 int main(void){ DIR *dp; FILE *rfp; struct dirent *d</string.h></dirent.h></stdio.h>…

C言語でDirectoryからファイルをひっぱり、ファイルの中を検索する

[root@gochamaze C]# cat directory.c#include <stdio.h>#include <dirent.h>#include <string.h> #define BUF 256 int main(void){ DIR *dp; FILE *rfp; struct dirent *dir; char *path = "/root/C/"; char buf[BUF]; char buf2[BUF]; char *sp; if *1 == NULL) { fprintf(stderr,"ERROR</string.h></dirent.h></stdio.h>…