Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
11
Добавлен:
09.06.2015
Размер:
1.16 Кб
Скачать
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <io.h>
#include <stdio.h>
#include <windows.h>
#include <winbase.h>
#include <wchar.h>
#include <malloc.h>
void main(int argv,char *argc[] )
{
HANDLE hf1;
FILE *outfile;
DWORD size,sizer;
wchar_t *uni;
char *ansi;
unsigned int codepage;
printf("Unicode to ANSI transformation of text files\n Copyright TNP Corporation 2001\n");
if(argv!=4){perror("Error syntax:\n Syntax: unic2ansi infile outfile codepage\n");
                     } 
hf1=CreateFile(argc[1],GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if(hf1==0)perror(strcat("filed open",argc[1]));
size=GetFileSize((HANDLE)hf1,NULL);
if(size==-1)perror("Error getting file size"); 
uni=malloc(size);
if(!ReadFile((HANDLE)hf1,uni,size,&sizer,NULL))perror("Error reading file");
if(!IsTextUnicode(uni,size,NULL))perror("gm... It is not Unicode Text");
ansi=malloc(size/2);
codepage=(unsigned int)atoi(argc[3]);
WideCharToMultiByte(codepage,0,uni,size/2,ansi,size/2,NULL,NULL);
outfile=fopen(argc[2],"wb");
fwrite(ansi,1,size/2,outfile);
fclose(outfile);
printf("done");
}




Соседние файлы в папке lecture11