0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

全角英数を半角にする

Last updated at Posted at 2015-05-20

メモを取ってると半角全角が入り乱れるので、英数字だけ置換しちゃいたかった。
置換だけできればいいのでやっつけ仕事

henkan.c

#include <stdio.h>

int main( void ){

 FILE *fp,*fpo;
 char *fname = "hogehoge.txt";
 char s[100];
 unsigned char *p;
 unsigned int moji;

 fp = fopen( fname, "r" );
 if( fp == NULL ){
    printf( "no open ?n");
    return -1;
 }
 fpo = fopen("hogehoge.dat","w");
 
 while( fgets( s, 100, fp ) != NULL ){
  for ( p = s ; *p != '\0' ; p += 2 ){
	moji = (p[0] << 8) | p[1];
	moji = _mbctombb( moji );

	if((p[0]==130)&&(p[1]<=154)){
		fprintf(fpo,"%c",moji);
	}else if((p[0]<=127)) {
		fprintf(fpo,"%c",p[0]);
		p=p-1;
	}else{
		fprintf(fpo,"%c%c",p[0], p[1]);}
  }
 }
  printf( "done ?n" );
  fclose( fp );
  fclose( fpo );
  return 0;
}

ファイルのパスを直に書いてるあたりすごいやっつけ仕事だった

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?