#ifndef _analys_h_
#define _analys_h_
#include #include "object.h"
#define fgetsmax 6*1024*1024 //獲取一行資料的最大值6m
class object;
class analys
; object(char *v, int l)
: value(v)
, length(l)
{}char* value;
int length;
}object;
*/};#endif
#include #include #include "analys.h"
using namespace std;
analys::analys()
m_dest = new char*[128];
for(int i = 0; i < 128; i++)
}analys::~analys()
deletem_dest;
deletem_obj;
delete m_linebuf;
}/**
* note :切分 字串
* * @param str: 待分割的字串
* @param delim: 分隔符字串
* @param dest: 儲存分割後的每個字串
* @param pcount: 記錄一行中分割所得的字串個數、也就是所謂的列數
* * @return : 正常返回0,字串為空或者長度為0,則返回-1
*/int analys::segment(char* str, char* delim, char** &dest, int* pcount, object** ob)
if(null == delim || 0 == strlen(delim))
tmp = strtok(str, delim);
int n = 0;
while(tmp != null)
return 0;
}/**
* node:將讀取到的一行資料寫到檔案中
* * @param obj:
* @param datacnt:列數(讀取一行的檔案)
* @param path:檔案的路徑
* * @return
*/int analys::loaddata(object** obj, int datacnt, file* fp, char *path)
fprintf(fp, "%s\n", obj[i]->value);
//fclose(fp);
return 0;
}/**
* note 將readpath ;路徑的檔案,讀取並解析,然後寫到writepath路徑下。
* * @param readpath :讀取檔案的路徑
* @param delim :解析檔案的分隔符
* @param writepath :讀完要寫入的檔案路徑
* * @return
*/int analys::rwdata(char* readpath, char* delim, char* writepath)
wfp = fopen(writepath, "wa");
if(wfp == null)
while(fgets(m_linebuf, fgetsmax, rfp) != null)
segment(m_linebuf, delim, m_dest, &count, m_obj);
loaddata(m_obj, count, wfp, writepath);
}fclose(rfp);
fclose(wfp);
return 0;
}int main(int argc, char *argv)
analys an;
an.rwdata(argv[1], "\t", argv[2]);
return 0;
}
Python 讀取檔案並分詞 檔案寫入
1 讀檔案 fr open file.txt for line in fr.readlines line line.strip listfromline line.split 簡單點寫 for line in open file.txt readlines listfromline line.str...
監聽Log 並寫入檔案
public class notelog public static void stopnotelog private static void startnotelogthread catch ioexception e finally readlogthread.start private sta...
查詢Mysql並寫入檔案
conding utf 8 import pymysql import os import sys 開啟資料庫連線 db pymysql.connect 10.33.85.145 root uxx 2013 使用 cursor 方法建立乙個游標物件 cursor runsql db.cursor 使...