Добавил:
Upload
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Информатика_1 / C / lecture11 / l11_5
.c/*1*/ /* This programm convert text file from unicode to ANSI text file
/*2*/ with codepage (866, 1251 ....) */
/*3*/ #include <stdio.h>
/*4*/ #include <windows.h>
/*5*/ #include <malloc.h>
/*6*/ void main(int argv,char *argc[] )
/*7*/ {
/*8*/ HANDLE hf1;
/*9*/ FILE *outfile;
/*10*/ DWORD size,sizer;
/*11*/ wchar_t *uni;
/*12*/ char *ansi;
/*13*/ unsigned int codepage;
/*14*/ printf("Unicode to ANSI transformation of text files\n Copyright BVV 2001\n");
/*15*/ if(argv!=4){perror("Error syntax:\n Syntax: unic2ansi infile outfile codepage\n");
/*16*/ }
/*17*/ //Open file argc[1] for read only
/*18*/ hf1=CreateFile(argc[1],GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
/*19*/ if(hf1==0)perror(strcat("filed open",argc[1]));
/*20*/ // get size of file in bytes
/*21*/ size=GetFileSize((HANDLE)hf1,NULL);
/*22*/ if(size==-1)perror("Error getting file size");
/*23*/ //get memory for buffer
/*24*/ uni=malloc(size);
/*25*/ // read file hf1 to buffer uni
/*26*/ if(!ReadFile((HANDLE)hf1,uni,size,&sizer,NULL))perror("Error reading file");
/*27*/ //to proove Is unicode text file?
/*28*/ if(!IsTextUnicode(uni,size,NULL))perror("gm... It is not Unicode Text");
/*29*/ // get memory for buffer ansi for converted text
/*30*/ ansi=malloc(size/2);
/*31*/ // get codepage
/*32*/ codepage=(unsigned int)atoi(argc[3]);
/*33*/ // To convert Unicode text from buffer uni to ANSI text to buffer ansi
/*34*/ // with codepage codepage
/*35*/ WideCharToMultiByte(codepage,0,uni,size/2,ansi,size/2,NULL,NULL);
/*36*/ //write result file
/*37*/ outfile=fopen(argc[2],"wb");
/*38*/ fwrite(ansi,1,size/2,outfile);
/*39*/ fclose(outfile);
/*40*/ printf("done");
/*41*/ }
/*42*/
/*43*/
Соседние файлы в папке lecture11