Created
December 16, 2008 21:31
-
-
Save vsalbaba/36832 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Tyto tri ulohy tvori prvni bodovanou praci! | |
| Vypracovat doma, odevzdat do pondeli do 5ti do rana | |
| 1. Nactete text z klavesnice, ulozte do souboru ve | |
| Windows 1250 | |
| 2. Nactete soubor (viz vysee) a vypiste na | |
| obrazovku | |
| 3. fopen umi pracovat i s unicode - vyzkousime | |
| Nactete a zobrazte Unicode soubor na | |
| obrazovce. (Soubor si vytvorte v Notepadu.) | |
| Pozn�mka: Nejprve si prectete "fopen" v MSDN. Kompilaci si | |
| pochopitelne prepnete do MBCS, tj. bez unicode. Konzola zobrazi | |
| jen cestinu, ale cizi unicode znaky ne (omezeni by design). | |
| */ | |
| #include "stdafx.h" | |
| #define BUFFER_SIZE 100 | |
| int _tmain(int argc, TCHAR *argv[]) | |
| { | |
| char input_line[BUFFER_SIZE]; // vstup z konzoly je vzdycky char, diky nastaveni na MBCS | |
| char buffer[BUFFER_SIZE]; | |
| int i, ch; | |
| FILE *output_file; | |
| printf("\n ukol cislo 1 - zadejte posloupnost znaku, jakkoli dlouhou, tu pak najdete v output_file.txt\n"); | |
| output_file = fopen("output_file.txt", "wt"); | |
| if(!output_file) { | |
| printf("Doslo k chybe pri nacteni souboru pro priklad 1"); | |
| return 1; | |
| } | |
| //konec osetreni vyjimek | |
| for (i = 0; (ch = getchar()) && (ch != '\n'); i++) | |
| { | |
| if (i == BUFFER_SIZE-1) { | |
| input_line[i] = '\0'; //protoze OemToChar je pyca a ocekava null terminated string | |
| i = 0; | |
| OemToChar(input_line, buffer); | |
| fprintf(output_file, "%s", buffer); | |
| } | |
| input_line[i] = (char) ch; | |
| } | |
| input_line[i] = '\0'; | |
| OemToChar(input_line, buffer); | |
| fprintf(output_file, "%s", buffer); | |
| fclose(output_file); | |
| //konec ukolu 1 - to same akorat naopak | |
| FILE *input_file; | |
| input_file = fopen("output_file.txt", "rt"); | |
| if(!input_file) { | |
| printf("Doslo k chybe pri nacteni souboru pro priklad 2"); | |
| return 1; | |
| } | |
| //konec osetreni vyjimek | |
| while (fgets(input_line, BUFFER_SIZE, input_file)) { | |
| CharToOem(input_line, buffer); | |
| printf("%s", buffer); | |
| } | |
| fclose(input_file); | |
| //konec ukolu 2 | |
| FILE *unicode_input_file; | |
| wchar_t winput_line[BUFFER_SIZE]; | |
| unicode_input_file = fopen("unicode_file.txt", "rt, ccs=UNICODE"); | |
| //osetreni vyjimek - nuda | |
| if(!unicode_input_file) { | |
| printf("Doslo k chybe pri nacteni souboru pro priklad 3\n"); | |
| return 1; | |
| } | |
| //konec osetreni vyjimek | |
| while (fgetws(winput_line, BUFFER_SIZE, unicode_input_file)) { | |
| CharToOemW(winput_line, buffer); //hnusna a zakerna funkce. kdyz k hezke funkci pridate W, stane se z ni oskliva pracujici s widecharem. | |
| printf("%s", buffer); | |
| } | |
| fclose(unicode_input_file); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment