- 追加された行はこの色です。
- 削除された行はこの色です。
[[Programming]]
とりあえず,こんなプログラムを書いてみた
#include <stdio.h>
#include <stdlib.h>
#include <locale>
using namespace std;
int main(int argc, char *argv[]){
char * input;
wchar_t * wbuf[1240];
/* ワイド文字列 : 日本語文字数 + 1 */
/* マルチバイトUTF-8 で漢字は3バイト,一文字取るなら 3 + 1 */
char str1[4] = { 0 };
char str2[4] = { 0 };
char gram2[7] = { 0 };
int test = 0;
FILE *fp;
char * p;
setlocale(LC_ALL,"");
printf("file = %s\n", argv[1]);
if((fp = fopen(argv[1], "r")) == NULL){
printf("file not found\n");
return(1);
}else{
while(!feof(fp)){
if(fgets(input, 1024, fp) != NULL){
p = strchr( input, '\n' );
/* 改行文字があった場合 */
if ( p != NULL )
{
/* 改行文字を終端文字に置き換える */
*p = '\0';
}
printf("size of input= %d\n", sizeof(input));
printf("strlen of input= %d\n", strlen(input));
if(strlen(input) > 0){
printf("%s\n", input);
mbstowcs(wbuf, input, strlen(input));
/* マルチバイト文字列をワイド文字列に変換*/
printf("strlen of wbuf = %d\n", wcslen(wbuf));
while(test < wcslen(wbuf) ){
wctomb(str1,wbuf[test]);
wctomb(str2,wbuf[test+1]);
sprintf(gram2, "%s%s",str1, str2);
// printf(" %s %s \n", str1, str2);
printf("%s\n",gram2);
// printf("%ls\n",wbuf);
test++;
}
}// while_2
}// _if
} //_while_1
}//_else
}
// _end_main