Programming_C のバックアップの現在との差分(No.3) - アールメカブ

アールメカブ


Programming_C のバックアップの現在との差分(No.3)


  • 追加された行はこの色です。
  • 削除された行はこの色です。
#contents
* 文字を区切る.文字長 [#jf396551]
strtok, strlen のワイド文字列版をすぐ忘れる wcstok と wcslen である.

* 文字コードの確認 [#tb3794e8]
-[[ここ:http://oss.timedia.co.jp/show/MySQL%E6%97%A5%E6%9C%AC%E8%AA%9E%E3%81%AE%E6%97%85/Linux%E3%81%AE16%E9%80%B2%E3%83%80%E3%83%B3%E3%83%97%E3%83%84%E3%83%BC%E3%83%AB(od,xxd)]]を参照

 $ echo -n '記号' | od -x
 0000000 a8e8 e598 b78f

とすると,マルチバイト文字ごとに,バイトの連なりが逆になってしまう.
そこで次のように処理する.

 $ echo -n '記号' | hexdump -C
 00000000  e8 a8 98 e5 8f b7  

* 単純な文字列渡し [#x63df67d]
 #include<iostream>
 #include <string.h>
 
 using namespace std;
 
 void test(char * input){
   cout << input << endl;
 }
 
 int main()
 {
   char input[5120];
   strcpy(input , "これはテスト");
   test(input);
   return 0;
 }


* コンテナクラスの参照渡し [#la2cf6c4]
 #include <map>
 #include <vector>
 #include<iostream>
 using namespace std;
 
 void setText(vector<string> &v, map <string, int> &m1,
           map<string, int>::iterator & pa){
 
  cout << "v.size = " << v.size();
  pa = m1.begin();// 
  for(int i = 0; i < v.size(); i++){
	
	//	pa = m1.find(v[i]);
 	if( (pa = m1.find(v[i])) != m1.end()){
	  //	if( (m1.find(v[i]))->second > 0){
               //すでにマップにあるのなら
	  cout << "find" << endl;
	  pa->second = pa->second + 1;
	  //	  (m1.find(v[i]))->second =
                    ( (m1.find(v[i]))->second) + 1;
	  //二つ目の数値を加算
	}
	else{// そうでないなら,データを挿入
	  // 	  pa.first = v[i];
	  // 	  pa.second = 1;
 	  m1.insert(make_pair(v[i], 1));
	  //	cout << "find " << endl;
	}
  }// end_for
 }
   
 int main()
 {
  vector<string> v;
  map<string, int> m1;
  map<string, int>::iterator pa;   
 
   v.push_back("加藤");
   v.push_back("鈴木");   
   v.push_back("佐藤");
   v.push_back("山田");
 
   setText(v,m1,pa );
   
  pa = m1.begin();
  int n = (int)m1.size();
  for(int i = 0; i < n; i++){
	cout << pa->first << " " << pa->second << endl;
	pa++;
  }
  
  return 0;
 }

その2
 #include <map>
 #include <vector>
 #include<iostream>
 using namespace std;
 void setText(vector<string> &v, map <string, int> & m1,
               map <string, int> & m2,     int z,  
       map<string, int>::iterator & pa, 
       map<string, int>::iterator & pa2 ){
 
  cout << "v.size = " << v.size();
  for(int i = 0; i < v.size(); i++){
	
 	if( (pa = m1.find(v[i])) != m1.end()){
	              
	  cout << "find in ma1" << endl;
	  pa->second = pa->second + 1;
	             
	}
	else{       // そうでないなら,データを挿入
	            // 	  pa.first = v[i];
	            // 	  pa.second = 1;
 	  m1.insert(make_pair(v[i], 1));
	            //	cout << "find " << endl;
	}
	              //	pa = m1.find(v[i]);
 	if( (pa2 = m2.find(v[i])) != m2.end()){
	   cout << "find in ma2" << endl;
	  pa2->second = pa2->second + 1;
	             //	  (m1.find(v[i]))->second =
             ( (m1.find(v[i]))->second) + 1;
	             //二つ目の数値を加算
	}
	else{       // そうでないなら,データを挿入
 	  m2.insert(make_pair(v[i], 1));
	}
	
  }// end_for
 }
  
 int main()
 {
  int i = 0;
  int j = 0;
  vector<string> v;
  map<string, int> m1,m2[2];
 
  map<string, int>::iterator pa, pa2;  
 
   v.push_back("加藤");
   v.push_back("鈴木");   
   v.push_back("佐藤");
   v.push_back("山田");
   for(i =0; i < 2; i++){
	 pa = m1.begin();
 	 pa2 = m2[i].begin();
	 //	 setText(v, m1, m2, i, pa, pa2);
 
	 setText(v, m1, m2[i], i, pa, pa2);
   }
  
 
  
  int n = (int)m1.size();
  pa = m1.begin();
  for(i = 0; i < n; i++){
	cout << pa->first << " " << pa->second << endl;
	pa++;
  }
  cout << "next" << endl;
  
  for(i = 0; i < 2; i++){
	cout << "i = " << i << endl;
	pa2 = m2[i].begin();
	  for(j = 0; j < n; j++){
		cout << "   j = " << j << endl;
		cout << "       " <<pa2->first << "       " 
        <<  pa2->second << endl;
		pa2++;
	  }
  }
  return 0;
 }

*[[コンパイラやOSのdefinedフラグについて:http://www.nbrains.net/php/pukiwiki/index.php?link%BD%B8%2F%B3%AB%C8%AF%B8%C0%B8%EC%B7%CF%2FC%2B%2B]] [#ib67e3b3]
*[[Vectorに納めたstringの取り出し]] [#a940ea3b]
*[[strtokとchar_strtok]] [#h35daddc]

*  [[マルチバイト文字とワイド文字の変換wcstok_wcstombs_etc>wcstok_wcstombs_etc]] [#o1f7c048]

* stringオブジェクトをprintfで表示 [#ef99228f]

よく忘れてはまる.pa は map <string,int> ma のイテレーターとする
 printf("word = %s: freq = %d\n", 
         (pa->first).c_str(), pa->second );
* [[mapコンテナから要素を削除する]] [#ib24655b]
*  [[malloc再考>hidden_malloc]] [#ca6ccbea]
* [[C_N-gram]] [#ha177611]
* [[C_日本語一文字を取得]] [#x344101e]
-* gcc-4.0だと、エンコーディングを指定してコンパイルする
ことができる.
 $ gcc -finput-charset=Shift_JIS hoge.c -o hoge.o
* [[hidden_C_N-gram]] [#j6e210da]
* [[hidden_C_CharCode]] [#sa14f81d]
*  [[ディレクトリ操作dirent.h]] [#q17036ad]
* [[strtokとmap]] [#l2926178]
* [[stringとchar]] [#n3161220]
* extern [#p19d2e87]
http://osdir.com/ml/gnu.mingw.user/2002/msg03869.html
>
"__declspec(dllimport)" and "extern
__declspec(dllexport)" both imply a declaration, but that
"__declspec(dllimport)" causes the linker to look for the __imp symbol in an
import library, while "extern __declspec(dllexport)" declares a function that must be defined in the program's source (no __imp prefix).
<

設定されている環境変数を表示するには、printenvコマンドを
* -fPIC は共有ライブラリ (*.so)を作成するオプション [#n843e3bd]
//http://oshiete1.goo.ne.jp/qa1936970.html
正確には,リンカの一に依存しないコードを生成する.&htmlinsert(amazontext,asin=4873113032,text=クックブック); p.34
* [[ライブラリの構築>http://docs.sun.com/source/806-4837/Building.html]]* [#aa3f5f90]
* [[Boost_regex]] [#vf944a8b]
* [[Cでメモリを節約して文字列を読む]] [#o088c089]
* [[C_INCLUDE_PATH]] [#fc0db8d7]
* [[ヘッダファイルの場所]] [#neb60e6b]
* [[sizeofについて]] [#a0365a3f]
* [[const_castの使い方]] [#c1caa9b7]
* [[C++とヘッダ]] [#k1aead24]
* [[Cで文字列を空にする]] [#qf247e2c]
* [[Cで動的に配列を作成する]] [#tf578c2e]
* [[C++での正規表現>CPP_regex]] [#hdd659fe]
* [[CPP_file_tokenize]] [#r5a2a3e8]
* [[CPP_vectorの使い方]] [#qda05f47]
* [[CPP_mapの使い方]] [#i20c6033]
* [[Prog_Mecab]] 和布蕪の出力処理 [#l20d392d]
* [[cin関数でのオーバーフロー>Programming_cin]] [#nb13260f]