Stránka: 1 z 1
| [ Príspevkov: 15 ] | |
Autor | Správa |
---|
Registrovaný: 01.05.05 Príspevky: 13415 Témy: 1496 | 1496 Bydlisko: Bratislava |
Kód: /* Uloha 11 (2b) - Napiste program, ktory zobrazi císlo 45967 a ASCII kod znaku 'A' v dvojkovej, desiatkovej a sestnastkovej sustave. */
#include <stdio.h>
void dec2bin(int dec, char *bin) { int k = 0, n = 0, remain; char doc[80]; do { remain = dec % 2; dec = dec / 2; doc[k++] = remain + '0'; } while (dec > 0); while (k >= 0) bin[n++] = doc[--k]; bin[n-1] = 0; }
int main() { int dec = 45967, ascii = 'A'; char bin[80];
dec2bin(dec,bin); printf("- Cislo 45967 -\nDvojkova sustava: %s\nDesiatkova sustava: %ld\nSestnastkova susava: %x\n\n", bin, dec, dec);
dec2bin(ascii,bin); printf("- ASCII kod znaku A -\nDvojkova sustava: %s\nDesiatkova sustava: %ld\nSestnastkova susava: %x\n", bin, ascii, ascii);
return 0; }
_________________ Streacom DA2 | SilverStone Titanium SX800-LTI 800W | ASRock X299E-ITX/ac | Intel Core i9-9980XE & be quiet! Dark Rock TF | Kingston HyperX Impact 64 GB DDR4 2666 MHz | NVIDIA Titan RTX 24 GB | Intel SSD Optane 905P 480 GB NVMe U.2 & Intel SSD 750 1,2 TB NVMe U.2 & Intel SSD 660p 2 TB NVMe M.2 & Seagate BackUp Plus Portable 56 TB USB | 55" 4K OLED Dell Alienware AW5520QF | Ergotron LX Wall Mount Keyboard Arm | Logitech Craft | Logitech G603 | Logitech F710 | Harman Kardon Sabre SB 35 & Sennheiser RS 175 | Microsoft Windows 11 Enterprise | APC Back-UPS BE-850 VA | Lenovo ThinkPad X250 & Microsoft Windows 11 Professional | iPhone 15 Pro 256 GB & Pitaka Aramid | SilverStone ML05B Milo | Corsair SF600 SFX 600W | ASRock X99E-ITX/ac | Intel Xeon E5-2683 v4 & NOCTUA NH-L12S | Kingston HyperX Savage 32 GB DDR4 2400 MHz | NVIDIA GeForce GT 710 1 GB | Intel SSD Optane Memory 32 GB NVMe M.2 & Intel SSD 730 240 GB SATA | Ubuntu 24.04.1 LTS |
|
Registrovaný: 01.05.05 Príspevky: 13415 Témy: 1496 | 1496 Bydlisko: Bratislava |
Kód: /* Uloha 12 (2b) - Napiste program, ktory dokaze zapisat zadene cislo (staci rozsah 1-100) rimskymi cislicami. */
#include <stdio.h>
int main() { int cislo = 101, i, v, x, l, c, d, m; while(cislo > 100) { printf("Zadaj cislo v rozsahu 1 az 100: "); scanf("%i", &cislo); } c = cislo/100; //100 l = cislo%100/50; //50 x = cislo%100%50/10; //10 v = cislo%100%50%10/5; //5 i = cislo%100%50%10%5/1; //1 printf("\nI = %i\nV = %i\nX = %i\nL = %i\nC = %i\n\nRimske cislo: ", i, v, x, l, c); if(c == 1) printf("C"); //100 if(l == 1 && x == 4) printf("XC"); //90-99 if(l == 1 && x != 4) printf("L"); //50 if(l == 0 && x == 4) printf("XL"); //40-49 if(x == 3) printf("XXX"); //30-39 if(x == 2) printf("XX"); //20-29 if(x == 1) printf("X"); //10-19 if(i == 4 && v%2 == 1) printf("IX"); //9 if(v == 1 && i != 4) printf("V"); //5 if(i == 4 && v%2 == 0) printf("IV"); //4 if(i == 3) printf("III"); //3 if(i == 2) printf("II"); //2 if(i == 1) printf("I"); //1 printf("\n"); return 0; }
_________________ Streacom DA2 | SilverStone Titanium SX800-LTI 800W | ASRock X299E-ITX/ac | Intel Core i9-9980XE & be quiet! Dark Rock TF | Kingston HyperX Impact 64 GB DDR4 2666 MHz | NVIDIA Titan RTX 24 GB | Intel SSD Optane 905P 480 GB NVMe U.2 & Intel SSD 750 1,2 TB NVMe U.2 & Intel SSD 660p 2 TB NVMe M.2 & Seagate BackUp Plus Portable 56 TB USB | 55" 4K OLED Dell Alienware AW5520QF | Ergotron LX Wall Mount Keyboard Arm | Logitech Craft | Logitech G603 | Logitech F710 | Harman Kardon Sabre SB 35 & Sennheiser RS 175 | Microsoft Windows 11 Enterprise | APC Back-UPS BE-850 VA | Lenovo ThinkPad X250 & Microsoft Windows 11 Professional | iPhone 15 Pro 256 GB & Pitaka Aramid | SilverStone ML05B Milo | Corsair SF600 SFX 600W | ASRock X99E-ITX/ac | Intel Xeon E5-2683 v4 & NOCTUA NH-L12S | Kingston HyperX Savage 32 GB DDR4 2400 MHz | NVIDIA GeForce GT 710 1 GB | Intel SSD Optane Memory 32 GB NVMe M.2 & Intel SSD 730 240 GB SATA | Ubuntu 24.04.1 LTS |
|
Registrovaný: 01.05.05 Príspevky: 13415 Témy: 1496 | 1496 Bydlisko: Bratislava |
Kód: /* Uloha 13 (3b) Napiste program, ktory zisti a vypise na obrazovku strojove epsilon pre typy float a double. Zaroven vypiste aj hodnoty __FLT_EPSILON__ a __DBL_EPSILON__) zadefinovanymi vo float.h. */
#include <stdio.h> #include <float.h>
int main() { float epsilon = 1.0f, sum; double epsilond = 1.0f, sumd;
do { epsilon = epsilon / 2.0f; sum = (float)(1.0 + (epsilon/2.0)); } while (sum != 1.0);
do { epsilond = epsilond / 2.0f; sumd = (double)(1.0 + (epsilond/2.0)); } while (sumd != 1.0);
printf("Vypocitane epsilon: %G\n", epsilon); printf("Vypocitane epsilon (double): %G", epsilond);
printf("\n\nFLT_EPSILON: %G", FLT_EPSILON); printf("\nDBL_EPSILON: %G\n", DBL_EPSILON);
return 0; }
_________________ Streacom DA2 | SilverStone Titanium SX800-LTI 800W | ASRock X299E-ITX/ac | Intel Core i9-9980XE & be quiet! Dark Rock TF | Kingston HyperX Impact 64 GB DDR4 2666 MHz | NVIDIA Titan RTX 24 GB | Intel SSD Optane 905P 480 GB NVMe U.2 & Intel SSD 750 1,2 TB NVMe U.2 & Intel SSD 660p 2 TB NVMe M.2 & Seagate BackUp Plus Portable 56 TB USB | 55" 4K OLED Dell Alienware AW5520QF | Ergotron LX Wall Mount Keyboard Arm | Logitech Craft | Logitech G603 | Logitech F710 | Harman Kardon Sabre SB 35 & Sennheiser RS 175 | Microsoft Windows 11 Enterprise | APC Back-UPS BE-850 VA | Lenovo ThinkPad X250 & Microsoft Windows 11 Professional | iPhone 15 Pro 256 GB & Pitaka Aramid | SilverStone ML05B Milo | Corsair SF600 SFX 600W | ASRock X99E-ITX/ac | Intel Xeon E5-2683 v4 & NOCTUA NH-L12S | Kingston HyperX Savage 32 GB DDR4 2400 MHz | NVIDIA GeForce GT 710 1 GB | Intel SSD Optane Memory 32 GB NVMe M.2 & Intel SSD 730 240 GB SATA | Ubuntu 24.04.1 LTS |
|
Registrovaný: 01.05.05 Príspevky: 13415 Témy: 1496 | 1496 Bydlisko: Bratislava |
Kód: /* Uloha 15 (4b) - Napiste program, ktory pre zadane n vypise pekne formatovany Pascalov trojuholnik s n riadkami. Naviac bude kazde parne cislo nahradene znakom * */
#include <stdio.h>
long faktorial(int cislo) { long f = 1; int i = 1; while(i <= cislo) { f = f * i; i++; } return f; }
int main() { int cislo, i, j, k; printf("Zadaj cislo: "); scanf("%i", &cislo); for(i = 0;i < cislo;i++) { for(j = 0;j < cislo - i;j++) printf(" "); for(j = 0;j <= i;j++) { if((faktorial(i) / (faktorial(j) * faktorial(i-j)))%2 == 0) printf("* "); else printf("%li ", faktorial(i) / (faktorial(j) * faktorial(i-j))); } printf("\n"); } printf("\n"); return 0; }
_________________ Streacom DA2 | SilverStone Titanium SX800-LTI 800W | ASRock X299E-ITX/ac | Intel Core i9-9980XE & be quiet! Dark Rock TF | Kingston HyperX Impact 64 GB DDR4 2666 MHz | NVIDIA Titan RTX 24 GB | Intel SSD Optane 905P 480 GB NVMe U.2 & Intel SSD 750 1,2 TB NVMe U.2 & Intel SSD 660p 2 TB NVMe M.2 & Seagate BackUp Plus Portable 56 TB USB | 55" 4K OLED Dell Alienware AW5520QF | Ergotron LX Wall Mount Keyboard Arm | Logitech Craft | Logitech G603 | Logitech F710 | Harman Kardon Sabre SB 35 & Sennheiser RS 175 | Microsoft Windows 11 Enterprise | APC Back-UPS BE-850 VA | Lenovo ThinkPad X250 & Microsoft Windows 11 Professional | iPhone 15 Pro 256 GB & Pitaka Aramid | SilverStone ML05B Milo | Corsair SF600 SFX 600W | ASRock X99E-ITX/ac | Intel Xeon E5-2683 v4 & NOCTUA NH-L12S | Kingston HyperX Savage 32 GB DDR4 2400 MHz | NVIDIA GeForce GT 710 1 GB | Intel SSD Optane Memory 32 GB NVMe M.2 & Intel SSD 730 240 GB SATA | Ubuntu 24.04.1 LTS |
|
Registrovaný: 01.05.05 Príspevky: 13415 Témy: 1496 | 1496 Bydlisko: Bratislava |
Kód: /* Uloha 17 (4b) Napiste program na vypocet kontrolnej sumy (checksum) pre zadany riadok tzv. IntelHex suboru. */
#include <stdio.h> #include <stdlib.h> #include <string.h>
#define x(c) ((c>='0' && c<='9') ? c-'0' : ((c>='A' && c<='F') ? c-'A'+10 : ((c>='a' && c<='f') ? c-'a'+10 : 0)))
int xtoi(char *hex); int main() { int dlzka, i, sucet=0; char zaznam[1000]; static char pom[2];
printf("Zadaj retazec: "); scanf("%s", &zaznam);
dlzka=strlen(zaznam);
for(i=1;i<dlzka-2;i+=2) { strncpy(pom, zaznam+i, 2); sucet=sucet+x(pom[0])*16+x(pom[1]); } printf("Kontrolny sucet (checksum) retazca je: %X\n", 256-sucet%256);
return 0; }
_________________ Streacom DA2 | SilverStone Titanium SX800-LTI 800W | ASRock X299E-ITX/ac | Intel Core i9-9980XE & be quiet! Dark Rock TF | Kingston HyperX Impact 64 GB DDR4 2666 MHz | NVIDIA Titan RTX 24 GB | Intel SSD Optane 905P 480 GB NVMe U.2 & Intel SSD 750 1,2 TB NVMe U.2 & Intel SSD 660p 2 TB NVMe M.2 & Seagate BackUp Plus Portable 56 TB USB | 55" 4K OLED Dell Alienware AW5520QF | Ergotron LX Wall Mount Keyboard Arm | Logitech Craft | Logitech G603 | Logitech F710 | Harman Kardon Sabre SB 35 & Sennheiser RS 175 | Microsoft Windows 11 Enterprise | APC Back-UPS BE-850 VA | Lenovo ThinkPad X250 & Microsoft Windows 11 Professional | iPhone 15 Pro 256 GB & Pitaka Aramid | SilverStone ML05B Milo | Corsair SF600 SFX 600W | ASRock X99E-ITX/ac | Intel Xeon E5-2683 v4 & NOCTUA NH-L12S | Kingston HyperX Savage 32 GB DDR4 2400 MHz | NVIDIA GeForce GT 710 1 GB | Intel SSD Optane Memory 32 GB NVMe M.2 & Intel SSD 730 240 GB SATA | Ubuntu 24.04.1 LTS |
|
Registrovaný: 01.05.05 Príspevky: 13415 Témy: 1496 | 1496 Bydlisko: Bratislava |
Kód: /* Uloha 211 - procesor (1b) Vlozte do C-programu kusok assemblerovskeho kodu, ktorym vypocitate sucet dvoch premennych. */
#include <stdio.h>
static int iCislo, iCislo2, iVysledok;
int main() { iCislo = 27; iCislo2 = 5; iVysledok = 0;
__asm { MOV EAX, iCislo ADD EAX, iCislo2 MOV iVysledok,EAX }
printf("Cislo1: %d\nCislo2: %d\n\nVysledok: %d\n",iCislo,iCislo2,iVysledok);
return(0); }
_________________ Streacom DA2 | SilverStone Titanium SX800-LTI 800W | ASRock X299E-ITX/ac | Intel Core i9-9980XE & be quiet! Dark Rock TF | Kingston HyperX Impact 64 GB DDR4 2666 MHz | NVIDIA Titan RTX 24 GB | Intel SSD Optane 905P 480 GB NVMe U.2 & Intel SSD 750 1,2 TB NVMe U.2 & Intel SSD 660p 2 TB NVMe M.2 & Seagate BackUp Plus Portable 56 TB USB | 55" 4K OLED Dell Alienware AW5520QF | Ergotron LX Wall Mount Keyboard Arm | Logitech Craft | Logitech G603 | Logitech F710 | Harman Kardon Sabre SB 35 & Sennheiser RS 175 | Microsoft Windows 11 Enterprise | APC Back-UPS BE-850 VA | Lenovo ThinkPad X250 & Microsoft Windows 11 Professional | iPhone 15 Pro 256 GB & Pitaka Aramid | SilverStone ML05B Milo | Corsair SF600 SFX 600W | ASRock X99E-ITX/ac | Intel Xeon E5-2683 v4 & NOCTUA NH-L12S | Kingston HyperX Savage 32 GB DDR4 2400 MHz | NVIDIA GeForce GT 710 1 GB | Intel SSD Optane Memory 32 GB NVMe M.2 & Intel SSD 730 240 GB SATA | Ubuntu 24.04.1 LTS |
|
Registrovaný: 01.05.05 Príspevky: 13415 Témy: 1496 | 1496 Bydlisko: Bratislava |
Kód: /* Uloha 212 - procesor (1b) Napiste pomocou vlozeneho (embedded) asembleru C-program v ktorom pouzijete vlastnu funkciu na nasobenie dvomi bez pouzitia sucinu. */
#include <stdio.h>
static int iCislo, iVysledok;
int main() { iCislo = 123; iVysledok = 0;
__asm { MOV EAX, iCislo SHL EAX, 1 MOV iVysledok,EAX }
printf("Cislo: %d\n\nVysledok: %d\n",iCislo,iVysledok);
return(0); }
_________________ Streacom DA2 | SilverStone Titanium SX800-LTI 800W | ASRock X299E-ITX/ac | Intel Core i9-9980XE & be quiet! Dark Rock TF | Kingston HyperX Impact 64 GB DDR4 2666 MHz | NVIDIA Titan RTX 24 GB | Intel SSD Optane 905P 480 GB NVMe U.2 & Intel SSD 750 1,2 TB NVMe U.2 & Intel SSD 660p 2 TB NVMe M.2 & Seagate BackUp Plus Portable 56 TB USB | 55" 4K OLED Dell Alienware AW5520QF | Ergotron LX Wall Mount Keyboard Arm | Logitech Craft | Logitech G603 | Logitech F710 | Harman Kardon Sabre SB 35 & Sennheiser RS 175 | Microsoft Windows 11 Enterprise | APC Back-UPS BE-850 VA | Lenovo ThinkPad X250 & Microsoft Windows 11 Professional | iPhone 15 Pro 256 GB & Pitaka Aramid | SilverStone ML05B Milo | Corsair SF600 SFX 600W | ASRock X99E-ITX/ac | Intel Xeon E5-2683 v4 & NOCTUA NH-L12S | Kingston HyperX Savage 32 GB DDR4 2400 MHz | NVIDIA GeForce GT 710 1 GB | Intel SSD Optane Memory 32 GB NVMe M.2 & Intel SSD 730 240 GB SATA | Ubuntu 24.04.1 LTS |
|
Registrovaný: 01.05.05 Príspevky: 13415 Témy: 1496 | 1496 Bydlisko: Bratislava |
Kód: /* Uloha 213 - procesor (2b) - Napiste pomocou vlozeneho asembleru C-program s funkciou na prevod cislice (0 - 15) na prislusny ASCII znak. Pre cisla 0 - 9 bude vystupom znak '0' - '9', pre cisla 10 - 15 znaky 'A' - 'F'. */
#include <stdio.h>
static int iCislo, iVysledok;
int main() { printf("Zadaj cislo od 0 do 15: "); scanf("%i", &iCislo);
__asm { MOV EAX, iCislo CMP EAX, 9 JG vecsie
MOV EBX, 48 ADD EAX, EBX JMP koniec
vecsie: MOV EBX, 55 ADD EAX, EBX
koniec: MOV iVysledok, EAX }
printf("\nASCII znak: %c\n", iVysledok);
return 0; }
_________________ Streacom DA2 | SilverStone Titanium SX800-LTI 800W | ASRock X299E-ITX/ac | Intel Core i9-9980XE & be quiet! Dark Rock TF | Kingston HyperX Impact 64 GB DDR4 2666 MHz | NVIDIA Titan RTX 24 GB | Intel SSD Optane 905P 480 GB NVMe U.2 & Intel SSD 750 1,2 TB NVMe U.2 & Intel SSD 660p 2 TB NVMe M.2 & Seagate BackUp Plus Portable 56 TB USB | 55" 4K OLED Dell Alienware AW5520QF | Ergotron LX Wall Mount Keyboard Arm | Logitech Craft | Logitech G603 | Logitech F710 | Harman Kardon Sabre SB 35 & Sennheiser RS 175 | Microsoft Windows 11 Enterprise | APC Back-UPS BE-850 VA | Lenovo ThinkPad X250 & Microsoft Windows 11 Professional | iPhone 15 Pro 256 GB & Pitaka Aramid | SilverStone ML05B Milo | Corsair SF600 SFX 600W | ASRock X99E-ITX/ac | Intel Xeon E5-2683 v4 & NOCTUA NH-L12S | Kingston HyperX Savage 32 GB DDR4 2400 MHz | NVIDIA GeForce GT 710 1 GB | Intel SSD Optane Memory 32 GB NVMe M.2 & Intel SSD 730 240 GB SATA | Ubuntu 24.04.1 LTS |
|
Registrovaný: 01.05.05 Príspevky: 13415 Témy: 1496 | 1496 Bydlisko: Bratislava |
Kód: /* Uloha 214 - procesor (3b) Napiste pomocou inline asembleru a instrukcie cpuid program, ktory zisti, aky typ procesora mate v pocitaci (Intel, AMD, Cyrix,...). */
#include <stdio.h>
static int iIn = 0, iEAX, iEBX, iECX, iEDX;
int main() { __asm { MOV EAX, iIn CPUID MOV iEAX,EAX MOV iEBX,EBX MOV iECX,ECX MOV iEDX,EDX }
printf("EAX: 0x%08lx EBX: 0x%08lx ECX: 0x%08lx EDX: 0x%08lx\n\n",iEAX,iEBX,iECX,iEDX); printf("Tvoj procesor je ");
switch(iEBX) { case 0x756e6547: printf("INTEL"); break; case 0x68747541: printf("AMD"); break; case 0x69727943: printf("Cyrix"); break; case 0x746e6543: printf("VIA"); break; case 0x20536953: printf("SiS"); break; case 0x65736952: printf("Rise"); break; case 0x20434d55: printf("UMC"); break; case 0x4778654e: printf("Nexgen"); break; case 0x646f6547: printf("National Semiconductor"); break; default : printf("neznamy"); } printf("\n"); return 0; }
_________________ Streacom DA2 | SilverStone Titanium SX800-LTI 800W | ASRock X299E-ITX/ac | Intel Core i9-9980XE & be quiet! Dark Rock TF | Kingston HyperX Impact 64 GB DDR4 2666 MHz | NVIDIA Titan RTX 24 GB | Intel SSD Optane 905P 480 GB NVMe U.2 & Intel SSD 750 1,2 TB NVMe U.2 & Intel SSD 660p 2 TB NVMe M.2 & Seagate BackUp Plus Portable 56 TB USB | 55" 4K OLED Dell Alienware AW5520QF | Ergotron LX Wall Mount Keyboard Arm | Logitech Craft | Logitech G603 | Logitech F710 | Harman Kardon Sabre SB 35 & Sennheiser RS 175 | Microsoft Windows 11 Enterprise | APC Back-UPS BE-850 VA | Lenovo ThinkPad X250 & Microsoft Windows 11 Professional | iPhone 15 Pro 256 GB & Pitaka Aramid | SilverStone ML05B Milo | Corsair SF600 SFX 600W | ASRock X99E-ITX/ac | Intel Xeon E5-2683 v4 & NOCTUA NH-L12S | Kingston HyperX Savage 32 GB DDR4 2400 MHz | NVIDIA GeForce GT 710 1 GB | Intel SSD Optane Memory 32 GB NVMe M.2 & Intel SSD 730 240 GB SATA | Ubuntu 24.04.1 LTS |
|
Registrovaný: 01.05.05 Príspevky: 13415 Témy: 1496 | 1496 Bydlisko: Bratislava |
Kód: /* Uloha 22 - pamat (3b) Viete uz pracovat so smernikmi (pointre). Viete ale, co je naozaj v pointri ulozene? Samozrejme, realna adresa. Deklarujte a priradte hodnoty do pola znakov, dalej smernik na toto pole a vypiste na obrazovku skutocnu adresu na ktoru ukazuje (napr. printf("%p",pointer) ). Potom zmente hodnotu adresy (pripocitajte jednotku). Zapiste nejaku hodnotu na tuto adresu. Co sa stalo? Nakoniec zmente hodnotu adresy na nejaku celkom inu, nahodne zvolenu. Co sa stane? Vysvetlite. */
#include <stdio.h>
int main() { int i; int pole[5], *pointer; pointer = &pole[0]; printf("Adresa pointer: %p\n\n", pointer);
for(i=0;i<5;i++) { pole[i] = i; printf("adresa pre pole[%i] - %p\n", pole[i], pointer+i); }
*(pointer+3) = 10; printf("\nAdresa pointer+3: %p\nNova hodnota: %i\n\n", pointer+3, *(pointer+3));
for(i=0;i<5;i++) { printf("adresa pre pole[%i] - %p\n", pole[i], pointer+i); }
*(pointer+15) = 60; printf("\nAdresa mimo pole - pointer+10: %p\nHodnota: %i\n\n", pointer+10, *(pointer+10));
return 0; }
_________________ Streacom DA2 | SilverStone Titanium SX800-LTI 800W | ASRock X299E-ITX/ac | Intel Core i9-9980XE & be quiet! Dark Rock TF | Kingston HyperX Impact 64 GB DDR4 2666 MHz | NVIDIA Titan RTX 24 GB | Intel SSD Optane 905P 480 GB NVMe U.2 & Intel SSD 750 1,2 TB NVMe U.2 & Intel SSD 660p 2 TB NVMe M.2 & Seagate BackUp Plus Portable 56 TB USB | 55" 4K OLED Dell Alienware AW5520QF | Ergotron LX Wall Mount Keyboard Arm | Logitech Craft | Logitech G603 | Logitech F710 | Harman Kardon Sabre SB 35 & Sennheiser RS 175 | Microsoft Windows 11 Enterprise | APC Back-UPS BE-850 VA | Lenovo ThinkPad X250 & Microsoft Windows 11 Professional | iPhone 15 Pro 256 GB & Pitaka Aramid | SilverStone ML05B Milo | Corsair SF600 SFX 600W | ASRock X99E-ITX/ac | Intel Xeon E5-2683 v4 & NOCTUA NH-L12S | Kingston HyperX Savage 32 GB DDR4 2400 MHz | NVIDIA GeForce GT 710 1 GB | Intel SSD Optane Memory 32 GB NVMe M.2 & Intel SSD 730 240 GB SATA | Ubuntu 24.04.1 LTS |
|
Registrovaný: 01.05.05 Príspevky: 13415 Témy: 1496 | 1496 Bydlisko: Bratislava |
Kód: /* Uloha 23 - disky (2b) Zo subormi ste uz pracovali. Stiahnite a ulozte si do suboru tento text poviedky. Je napisany v kodovaní ISO-8859-2, ale aby ste ho vo Windows mohli poriadne precitat, musi byt v kodovaní CP-1250. Nastastie sa tieto dve kodovania lisia len v niekolkych znakoch. Napiste program, ktory text prevedie do spravneho kodovania. */
#include <stdio.h> #include <stdlib.h>
int main() { FILE *prvy; FILE *druhy; int c;
prvy=fopen("poviedka.htm","r"); druhy=fopen("poviedka2.htm","w");
while((c=fgetc(prvy)) != EOF) { switch(c) { case 165: c=188; break; case 169: c=138; break; case 171: c=141; break; case 174: c=142; break; case 181: c=190; break; case 185: c=154; break; case 187: c=157; break; case 190: c=158; break; } fputc(c,druhy); } fclose(prvy); fclose(druhy);
return 0; }
_________________ Streacom DA2 | SilverStone Titanium SX800-LTI 800W | ASRock X299E-ITX/ac | Intel Core i9-9980XE & be quiet! Dark Rock TF | Kingston HyperX Impact 64 GB DDR4 2666 MHz | NVIDIA Titan RTX 24 GB | Intel SSD Optane 905P 480 GB NVMe U.2 & Intel SSD 750 1,2 TB NVMe U.2 & Intel SSD 660p 2 TB NVMe M.2 & Seagate BackUp Plus Portable 56 TB USB | 55" 4K OLED Dell Alienware AW5520QF | Ergotron LX Wall Mount Keyboard Arm | Logitech Craft | Logitech G603 | Logitech F710 | Harman Kardon Sabre SB 35 & Sennheiser RS 175 | Microsoft Windows 11 Enterprise | APC Back-UPS BE-850 VA | Lenovo ThinkPad X250 & Microsoft Windows 11 Professional | iPhone 15 Pro 256 GB & Pitaka Aramid | SilverStone ML05B Milo | Corsair SF600 SFX 600W | ASRock X99E-ITX/ac | Intel Xeon E5-2683 v4 & NOCTUA NH-L12S | Kingston HyperX Savage 32 GB DDR4 2400 MHz | NVIDIA GeForce GT 710 1 GB | Intel SSD Optane Memory 32 GB NVMe M.2 & Intel SSD 730 240 GB SATA | Ubuntu 24.04.1 LTS |
|
Registrovaný: 01.05.05 Príspevky: 13415 Témy: 1496 | 1496 Bydlisko: Bratislava |
Kód: /* Uloha 24 - disky (1b) Zaujima vas, ako to dopadlo v pribehu z ulohy 2.3? Pokracovanie si mozete stiahnut odtialto. Aha, ze sa neda precitat? Musite ho rozsifrovat. Nastastie je pouzita velmi jednoducha sifra. Na kazdy znak je aplikovana operacia logicky XOR s cislom 27. Napiste program, ktory precita text zo suboru a kazdy znak pred vypisom dekoduje. */
#include <stdio.h> #include <stdlib.h>
int main() { FILE *prvy; FILE *druhy;
int c;
prvy=fopen("koniec.htm","r"); druhy=fopen("koniec2.htm","w");
while((c=getc(prvy))!=EOF) { c=(c^27); putc(c,druhy); }
fclose(prvy); fclose(druhy);
return 0; }
_________________ Streacom DA2 | SilverStone Titanium SX800-LTI 800W | ASRock X299E-ITX/ac | Intel Core i9-9980XE & be quiet! Dark Rock TF | Kingston HyperX Impact 64 GB DDR4 2666 MHz | NVIDIA Titan RTX 24 GB | Intel SSD Optane 905P 480 GB NVMe U.2 & Intel SSD 750 1,2 TB NVMe U.2 & Intel SSD 660p 2 TB NVMe M.2 & Seagate BackUp Plus Portable 56 TB USB | 55" 4K OLED Dell Alienware AW5520QF | Ergotron LX Wall Mount Keyboard Arm | Logitech Craft | Logitech G603 | Logitech F710 | Harman Kardon Sabre SB 35 & Sennheiser RS 175 | Microsoft Windows 11 Enterprise | APC Back-UPS BE-850 VA | Lenovo ThinkPad X250 & Microsoft Windows 11 Professional | iPhone 15 Pro 256 GB & Pitaka Aramid | SilverStone ML05B Milo | Corsair SF600 SFX 600W | ASRock X99E-ITX/ac | Intel Xeon E5-2683 v4 & NOCTUA NH-L12S | Kingston HyperX Savage 32 GB DDR4 2400 MHz | NVIDIA GeForce GT 710 1 GB | Intel SSD Optane Memory 32 GB NVMe M.2 & Intel SSD 730 240 GB SATA | Ubuntu 24.04.1 LTS |
|
Registrovaný: 01.05.05 Príspevky: 13415 Témy: 1496 | 1496 Bydlisko: Bratislava |
Kód: /* Uloha 26 grafika - farby (1b) Napiste program, ktory bude postupne vypisovat cisla od 0 po 10, pricom v zavislosti od velkosti cisla sa bude menit jeho farba, napriklad pre cisla od 0 po 2 bude zelena, 3 az 7 cervena a 8 az 10 modra. Rychlost vypisu na obrazovku obmedzte na cca 1 znak/sekundu. */
#include <windows.h> #include <stdio.h>
int main() { SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 10); printf("000\n"); Sleep(1000); printf("001\n"); Sleep(1000); printf("002\n"); Sleep(1000); SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 12); printf("003\n"); Sleep(1000); printf("004\n"); Sleep(1000); printf("005\n"); Sleep(1000); printf("006\n"); Sleep(1000); printf("007\n"); Sleep(1000); SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 9); printf("008\n"); Sleep(1000); printf("009\n"); Sleep(1000); printf("010\n"); Sleep(1000); SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 7);
return 0; }
_________________ Streacom DA2 | SilverStone Titanium SX800-LTI 800W | ASRock X299E-ITX/ac | Intel Core i9-9980XE & be quiet! Dark Rock TF | Kingston HyperX Impact 64 GB DDR4 2666 MHz | NVIDIA Titan RTX 24 GB | Intel SSD Optane 905P 480 GB NVMe U.2 & Intel SSD 750 1,2 TB NVMe U.2 & Intel SSD 660p 2 TB NVMe M.2 & Seagate BackUp Plus Portable 56 TB USB | 55" 4K OLED Dell Alienware AW5520QF | Ergotron LX Wall Mount Keyboard Arm | Logitech Craft | Logitech G603 | Logitech F710 | Harman Kardon Sabre SB 35 & Sennheiser RS 175 | Microsoft Windows 11 Enterprise | APC Back-UPS BE-850 VA | Lenovo ThinkPad X250 & Microsoft Windows 11 Professional | iPhone 15 Pro 256 GB & Pitaka Aramid | SilverStone ML05B Milo | Corsair SF600 SFX 600W | ASRock X99E-ITX/ac | Intel Xeon E5-2683 v4 & NOCTUA NH-L12S | Kingston HyperX Savage 32 GB DDR4 2400 MHz | NVIDIA GeForce GT 710 1 GB | Intel SSD Optane Memory 32 GB NVMe M.2 & Intel SSD 730 240 GB SATA | Ubuntu 24.04.1 LTS |
|
Registrovaný: 01.05.05 Príspevky: 13415 Témy: 1496 | 1496 Bydlisko: Bratislava |
Kód: /* Uloha 28 - grafika (3b) Aj v konzolovom rezime je mozne kreslit obrazky. Nahrajte si tento vzorovy program a na jeho zaklade nakreslite nejaky zlozitejsi obrazok (domcek, stromcek, hviezdicku,...). */
/* ************************************************************************** */ /* */ /* Architektura pocitacov - Uloha 2.8 */ /* */ /* Zaklady grafiky - ciara a kruznica. */ /* Funkcie prevzate z http://www.daniweb.com/code/showsnippet.php?codeid=173 */ /* */ /* Priklad, ako nakreslit ciary a kruznice do konzoloveho okna pod Windows */ /* Aplikacia musi byt konzolova, pri preklade treba pridat kniznicu, ak sa */ /* tak neudeje automaticky. Autorom funkcii je Sir Joe Caverly, preklad do */ /* jazyka C a modifikacia aj pre Dev-C++ autor "vegaseat". */ /* */ /* V MSVC treba pridat kniznicu GDI32.lib, pre Dev-C++ zasa libgdi32.a */ /* (Project >> Project Options >> Parameters >> Add Lib >> libgdi32.a) */ /* */ /* Autor: Vid. vyssie */ /* Historia: */ /* 16. 3. 2006 verzia 0 */ /* Prenositelnost: */ /* Len pre Windows */ /* ************************************************************************** */
#include <stdio.h> #include <windows.h> // Win32API Header File
#define Red RGB (255,0,0) // definicia vlastnych farieb (Red+Green+Blue) #define Lime RGB (206,255,0) #define Blue RGB (0,0,255) #define White RGB (255,255,255)
// nasleduje deklaracia troch funkcii, ktore // budeme pouzivat, definica na konci programu
int BCX_Line (HWND,int,int,int,int,int,HDC); // kresli ciaru int BCX_Circle (HWND,int,int,int,int,int,HDC); // kresli kruznicu HWND GetConsoleWndHandle (void); // ziska handle na okno
/* ************************************************************************** */ /* */ /* Tu zacina hlavny program */ /* */ /* ************************************************************************** */
int main(int argc, char *argv[]) {
static HWND hConWnd; hConWnd = GetConsoleWndHandle(); // ziskanie handle na okno
// tu zacina priestor pre vasu tvorivost: BCX_Line(hConWnd, 159, 62, 200, 119, Red,0); BCX_Line(hConWnd, 200, 119, 267, 97, Red,0); BCX_Line(hConWnd, 267, 97, 226, 154, Red,0); BCX_Line(hConWnd, 226, 154, 267, 210, Red,0); BCX_Line(hConWnd, 267, 210, 200, 189, Red,0); BCX_Line(hConWnd, 200, 189, 159, 245, Red,0); BCX_Line(hConWnd, 159, 245, 159, 175, Red,0); BCX_Line(hConWnd, 159, 175, 92, 154, Red,0); BCX_Line(hConWnd, 92, 154, 159, 132, Red,0); BCX_Line(hConWnd, 159, 132, 159, 62, Red,0);
BCX_Line(hConWnd, 341, 63, 393, 93, Lime,0); BCX_Line(hConWnd, 393, 93, 445, 63, Lime,0); BCX_Line(hConWnd, 445, 63, 445, 123, Lime,0); BCX_Line(hConWnd, 445, 123, 497, 153, Lime,0); BCX_Line(hConWnd, 497, 153, 445, 183, Lime,0); BCX_Line(hConWnd, 445, 183, 445, 243, Lime,0); BCX_Line(hConWnd, 445, 243, 393, 213, Lime,0); BCX_Line(hConWnd, 393, 213, 341, 243, Lime,0); BCX_Line(hConWnd, 341, 243, 341, 183, Lime,0); BCX_Line(hConWnd, 341, 183, 289, 153, Lime,0); BCX_Line(hConWnd, 289, 153, 341, 123, Lime,0); BCX_Line(hConWnd, 341, 123, 341, 63, Lime,0); BCX_Circle(hConWnd, 189, 153, 30, Blue,0,0); BCX_Circle(hConWnd, 189, 153, 25, Blue,0,0); BCX_Circle(hConWnd, 189, 153, 20, Blue,0,0); BCX_Circle(hConWnd, 189, 153, 15, Blue,0,0); BCX_Circle(hConWnd, 189, 153, 10, Blue,0,0); BCX_Circle(hConWnd, 189, 153, 5, Blue,0,0);
BCX_Line(hConWnd, 364, 194, 364, 147, White,0); BCX_Line(hConWnd, 364, 147, 424, 147, White,0); BCX_Line(hConWnd, 424, 147, 424, 194, White,0); BCX_Line(hConWnd, 424, 194, 364, 194, White,0); BCX_Line(hConWnd, 375, 194, 375, 162, White,0); BCX_Line(hConWnd, 375, 162, 387, 162, White,0); BCX_Line(hConWnd, 387, 162, 387, 194, White,0); BCX_Line(hConWnd, 383, 179, 387, 179, White,0); BCX_Line(hConWnd, 399, 162, 413, 162, White,0); BCX_Line(hConWnd, 413, 162, 413, 174, White,0); BCX_Line(hConWnd, 413, 174, 399, 174, White,0); BCX_Line(hConWnd, 399, 174, 399, 162, White,0); BCX_Line(hConWnd, 399, 168, 413, 168, White,0); BCX_Line(hConWnd, 406, 162, 406, 174, White,0); BCX_Line(hConWnd, 364, 147, 393, 123, White,0); BCX_Line(hConWnd, 393, 123, 424, 147, White,0); BCX_Line(hConWnd, 406, 133, 406, 124, White,0); BCX_Line(hConWnd, 411, 137, 411, 124, White,0); BCX_Line(hConWnd, 404, 124, 413, 124, White,0);
return 0; }
/* ************************************************************************** */ /* */ /* Nasleduju definicie funkcii, nepredpoklada sa, ze by ste tu cokolvek */ /* menili, ale nie je to zakazane, mozete tak docielit mnohe zaujimave */ /* efekty... */ /* */ /* ************************************************************************** */
/* ************************************************************************** */ /* */ /* Funkcia BCX_Line */ /* */ /* HWND Wnd : handle okna */ /* int x1, y1 : suradnice pociatocneho bodu */ /* int x2, y2 : suradnice koncoveho bodu */ /* int Pen : farba */ /* HDC DrawHDC : kontext zariadenia */ /* */ /* Funkcia nakresli ciaru z bodu [x1,y1] do bodu [x2,y2] farbou Pen. */ /* */ /* ************************************************************************** */
int BCX_Line (HWND Wnd,int x1,int y1,int x2,int y2,int Pen,HDC DrawHDC) { int a,b=0; HPEN hOPen; HPEN hNPen = CreatePen(PS_SOLID, 2, Pen); // penstyle, width, color if (!DrawHDC) DrawHDC = GetDC(Wnd), b = 1; hOPen = (HPEN)SelectObject(DrawHDC, hNPen); MoveToEx(DrawHDC, x1, y1, NULL); // starting point of line a = LineTo(DrawHDC, x2, y2); // ending point of line DeleteObject(SelectObject(DrawHDC,hOPen)); if (b) ReleaseDC(Wnd, DrawHDC); return a; }
/* ************************************************************************** */ /* */ /* Funkcia BCX_Circle */ /* */ /* HWND Wnd : handle okna */ /* int X, Y : suradnice stredu kruznice */ /* int R : polomer */ /* int Pen : farba */ /* int Fill : vypln */ /* HDC DrawHDC : kontext zariadenia */ /* */ /* Funkcia nakresli kruznicu so stredom [X,Y], polomerom R farbou Pen. */ /* */ /* Kruznicu kresli pomocou WinApi funkcie na kreslenie elipsy */ /* zadanej ohranicujucim obdlznikom so suradnicami laveho horneho */ /* a praveho dolneho rohu. /* */ /* ************************************************************************** */
int BCX_Circle(HWND Wnd,int X,int Y,int R,int Pen,int Fill,HDC DrawHDC) { int a, b = 0; if (!DrawHDC) DrawHDC = GetDC(Wnd), b = 1;
HPEN hNPen = CreatePen(PS_SOLID, 2, Pen); // penstyle, width, color HPEN hOPen = (HPEN)SelectObject(DrawHDC, hNPen); HBRUSH hOldBrush; HBRUSH hNewBrush; if (Fill) // if true will fill circle with pencolor { hNewBrush = CreateSolidBrush(Pen); hOldBrush = (HBRUSH)SelectObject(DrawHDC, hNewBrush); } else // else just draw circle { hNewBrush = (HBRUSH)GetStockObject(NULL_BRUSH); hOldBrush = (HBRUSH)SelectObject(DrawHDC, hNewBrush); }
a = Ellipse(DrawHDC, X-R, Y+R, X+R, Y-R);
DeleteObject(SelectObject(DrawHDC, hOPen)); DeleteObject(SelectObject(DrawHDC, hOldBrush)); if (b) ReleaseDC(Wnd, DrawHDC); return a; }
/* ************************************************************************** */ /* */ /* Funkcia GetConsoleWndHandle(void) */ /* */ /* ************************************************************************** */ // the hoop ...
HWND GetConsoleWndHandle(void) { HWND hConWnd;
OSVERSIONINFO os; char szTempTitle[64], szClassName[128], szOriginalTitle[1024];
os.dwOSVersionInfoSize = sizeof( OSVERSIONINFO ); GetVersionEx( &os ); // may not work on WIN9x if ( os.dwPlatformId == VER_PLATFORM_WIN32s ) return 0;
GetConsoleTitle( szOriginalTitle, sizeof( szOriginalTitle ) ); sprintf( szTempTitle,"%u - %u", GetTickCount(), GetCurrentProcessId() ); SetConsoleTitle( szTempTitle ); Sleep( 40 );
// handle for NT hConWnd = FindWindow( NULL, szTempTitle ); SetConsoleTitle( szOriginalTitle );
// may not work on WIN9x if ( os.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS ) { hConWnd = GetWindow( hConWnd, GW_CHILD ); if ( hConWnd == NULL ) return 0; GetClassName( hConWnd, szClassName, sizeof ( szClassName ) ); while ( strcmp( szClassName, "ttyGrab" ) != 0 ) { hConWnd = GetNextWindow( hConWnd, GW_HWNDNEXT ); if ( hConWnd == NULL ) return 0; GetClassName( hConWnd, szClassName, sizeof( szClassName ) ); } }
return hConWnd; }
_________________ Streacom DA2 | SilverStone Titanium SX800-LTI 800W | ASRock X299E-ITX/ac | Intel Core i9-9980XE & be quiet! Dark Rock TF | Kingston HyperX Impact 64 GB DDR4 2666 MHz | NVIDIA Titan RTX 24 GB | Intel SSD Optane 905P 480 GB NVMe U.2 & Intel SSD 750 1,2 TB NVMe U.2 & Intel SSD 660p 2 TB NVMe M.2 & Seagate BackUp Plus Portable 56 TB USB | 55" 4K OLED Dell Alienware AW5520QF | Ergotron LX Wall Mount Keyboard Arm | Logitech Craft | Logitech G603 | Logitech F710 | Harman Kardon Sabre SB 35 & Sennheiser RS 175 | Microsoft Windows 11 Enterprise | APC Back-UPS BE-850 VA | Lenovo ThinkPad X250 & Microsoft Windows 11 Professional | iPhone 15 Pro 256 GB & Pitaka Aramid | SilverStone ML05B Milo | Corsair SF600 SFX 600W | ASRock X99E-ITX/ac | Intel Xeon E5-2683 v4 & NOCTUA NH-L12S | Kingston HyperX Savage 32 GB DDR4 2400 MHz | NVIDIA GeForce GT 710 1 GB | Intel SSD Optane Memory 32 GB NVMe M.2 & Intel SSD 730 240 GB SATA | Ubuntu 24.04.1 LTS |
|
Registrovaný: 01.05.05 Príspevky: 13415 Témy: 1496 | 1496 Bydlisko: Bratislava |
Kód: /* Uloha -- projekt (12b.) Naprogramujte jednoduchy terminalovy program, pomocou ktoreho si budete moct pisat so susednym pocitacom prepojenym seriovym kablom. Program bude mat dve okienka na prijaty a odosielany text, moznosti volby prenosovej rychlosti a portu, archivaciu do suboru. */
#include <stdio.h> #include <conio.h> #include <windows.h>
int read(HANDLE hCom); int write(char vstup, HANDLE hCom); int baud(int vstup, HANDLE hCom); int dcb(HANDLE hCom); int main(int argc, char *argv[]) { int menu, submenu1, c, d, riadok = 0, timeout = 20, pomocnik; HANDLE hCom; HANDLE hConsole; hConsole = GetStdHandle(STD_OUTPUT_HANDLE); hCom = CreateFile( "COM1:", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if ( hCom == INVALID_HANDLE_VALUE ) { printf("Chyba: Port sa neda otvorit.\n"); CloseHandle(hCom); return 0; } else { printf("Port bol uspesne otvoreny.\n"); Sleep(500); } COMMTIMEOUTS timeouts; timeouts.ReadIntervalTimeout = timeout; timeouts.ReadTotalTimeoutMultiplier = 10; timeouts.ReadTotalTimeoutConstant = 100; timeouts.WriteTotalTimeoutMultiplier = 10; timeouts.ReadTotalTimeoutConstant = 100; if (!SetCommTimeouts(hCom, &timeouts)) { printf("Chyba: Timeouty nenastavene.\n"); CloseHandle(hCom); return 0; } else { printf("Timeouty nastavene na %d ms.\n", timeout); Sleep(500); } baud(1200, hCom); dcb(hCom); while(1) { if(kbhit()) { menu = getch(); if(menu == 27) break; if(menu == 59) { SetConsoleTextAttribute(hConsole, 7); printf("\nRychlost:\n1)\t 1200 Baud\n2)\t 2400 Baud\n3)\t 4800 Baud\n4)\t 9600 Baud\n5)\t 28800 Baud\n6)\t 57600 Baud\n7)\t 115200 Baud\n8)\t 230400 Baud\n9)\t 921600 Baud\n"); while(1) { if(kbhit()) { submenu1 = getch(); if(submenu1 == '1') { baud(1200, hCom); break; } if(submenu1 == '2') { baud(2400, hCom); break; } if(submenu1 == '3') { baud(4800, hCom); break; } if(submenu1 == '4') { baud(9600, hCom); break; } if(submenu1 == '5') { baud(28800, hCom); break; } if(submenu1 == '6') { baud(57600, hCom); break; } if(submenu1 == '7') { baud(115200, hCom); break; } if(submenu1 == '8') { baud(230400, hCom); break; } if(submenu1 == '9') { baud(921600, hCom); break; } } } } if(menu == 60) { SetConsoleTextAttribute(hConsole, 7); printf("\nMomentalne nastavene na %d ms.\nNove nastavenie (ms): ", timeout); scanf("%i", &timeout); COMMTIMEOUTS timeouts; timeouts.ReadIntervalTimeout = timeout; timeouts.ReadTotalTimeoutMultiplier = 10; timeouts.ReadTotalTimeoutConstant = 100; timeouts.WriteTotalTimeoutMultiplier = 10; timeouts.ReadTotalTimeoutConstant = 100; if (!SetCommTimeouts(hCom, &timeouts)) { printf("Chyba: Timeouty nenastavene.\n"); CloseHandle(hCom); return 0; } else { printf("Timeouty nastavene na %d ms.\n", timeout); Sleep(500); } dcb(hCom); } if(menu == 61) { printf("\nKlavesou ESC sa ukonci komunikacia.\nKlavesou F1 sa odosle 100 krat znak X.\nText: "); while(1) { SetConsoleTextAttribute(hConsole, 14); if(kbhit()) { c = getch(); if(riadok == 1) { printf("\n"); riadok = 0; } printf("%c", c); if(c == '\r') printf("\n"); if(c == 27) { SetConsoleTextAttribute(hConsole, 7); Sleep(500); printf("\nZatvara sa.\n"); dcb(hCom); break; } if(c == 59) { int i; for(i = 0; i < 100; i++) { write('X', hCom); } printf("\nZnak X odoslany.\n"); } write(c, hCom); } SetConsoleTextAttribute(hConsole, 12); if((d = read(hCom)) != 1) { if(riadok == 0) { printf("\n"); riadok = 1; } printf("%c", d); } } } if(menu == 62) { SetConsoleTextAttribute(hConsole, 7); printf("\nPomocnik k programu:\n--------------------\nPri spusteni programu sa otvori port (COM1). Ak je problem s portom, program vypise chybovu hlasku a ukonci sa. Po spravnom otvoreni portu sa zobrazi hlavne menu, kde sa na zaciatku nacita aktualna rychlost.\n\nHlavne menu:\nF1 - pomocou tejto klavesy sa nastavuje rychlost (9 prednastavenych).\nF2 - pomocou tejto klavesy sa nastavuju timeouty (prednastavenych 20 ms).\nF3 - pomocou tejto klavesy sa spusti komunikacia.\n * F1: posle 100 krat znak X\n * ESC: ukonci komunikaciu a vrati sa spet do hlavneho menu.\nESC - pomocou tejto klavesy sa program ukonci a zavrie port.\n\nStlac lubovolnu klavesu pre navrat do hlavneho menu."); while(1) { if(pomocnik = getch()) { Sleep(500); printf("\nZatvara sa.\n"); dcb(hCom); break; } } } } } CloseHandle(hCom); SetConsoleTextAttribute(hConsole, 7); system("cls"); printf("Port bol uspesne zatvoreny.\n"); Sleep(1000); return 0; }
int read(HANDLE hCom) { DWORD Pocet = 0; int Data; ReadFile( hCom, &Data, 1, &Pocet, NULL); if(Pocet != 1) return 1; return Data; }
int write(char vstup, HANDLE hCom) { DWORD Pocet = 0; unsigned char Data = vstup; WriteFile( hCom, &Data, 1, &Pocet, NULL); if(Pocet != 1) return 1; if(vstup == '\r') write('\n', hCom); return 0; }
int baud(int vstup, HANDLE hCom) { int Data = vstup; DCB PortDCB; PortDCB.DCBlength = sizeof(DCB); GetCommState(hCom, &PortDCB); PortDCB.BaudRate = Data; PortDCB.Parity = 0; PortDCB.ByteSize = 8; PortDCB.StopBits = 0; printf("Nastavene = rychlost: %d, parita: %d, pocet bitov: %d, stop bitov: %d.\n", PortDCB.BaudRate, PortDCB.Parity, PortDCB.ByteSize, PortDCB.StopBits); int err; err = SetCommState(hCom, &PortDCB); if(!err) { printf("Chyba: Port sa neda nakonfigurovat.\n"); CloseHandle(hCom); return 0; } else { printf("Port bol uspesne nakonfigurovany.\n"); Sleep(500); } dcb(hCom); return 0; }
int dcb(HANDLE hCom) { DCB PortDCB; PortDCB.DCBlength = sizeof(DCB); GetCommState(hCom, &PortDCB); Sleep(500); system("cls"); printf("Nacitane = rychlost: %d, parita: %d, pocet bitov: %d, stop bitov: %d.\nNastavit rychlost: F1\nNastavit timeouty: F2\nKomunikovat: F3\nPomocnik: F4\nKoniec:\tESC\n", PortDCB.BaudRate, PortDCB.Parity, PortDCB.ByteSize, PortDCB.StopBits); return 0; }
_________________ Streacom DA2 | SilverStone Titanium SX800-LTI 800W | ASRock X299E-ITX/ac | Intel Core i9-9980XE & be quiet! Dark Rock TF | Kingston HyperX Impact 64 GB DDR4 2666 MHz | NVIDIA Titan RTX 24 GB | Intel SSD Optane 905P 480 GB NVMe U.2 & Intel SSD 750 1,2 TB NVMe U.2 & Intel SSD 660p 2 TB NVMe M.2 & Seagate BackUp Plus Portable 56 TB USB | 55" 4K OLED Dell Alienware AW5520QF | Ergotron LX Wall Mount Keyboard Arm | Logitech Craft | Logitech G603 | Logitech F710 | Harman Kardon Sabre SB 35 & Sennheiser RS 175 | Microsoft Windows 11 Enterprise | APC Back-UPS BE-850 VA | Lenovo ThinkPad X250 & Microsoft Windows 11 Professional | iPhone 15 Pro 256 GB & Pitaka Aramid | SilverStone ML05B Milo | Corsair SF600 SFX 600W | ASRock X99E-ITX/ac | Intel Xeon E5-2683 v4 & NOCTUA NH-L12S | Kingston HyperX Savage 32 GB DDR4 2400 MHz | NVIDIA GeForce GT 710 1 GB | Intel SSD Optane Memory 32 GB NVMe M.2 & Intel SSD 730 240 GB SATA | Ubuntu 24.04.1 LTS |
|
Stránka: 1 z 1
| [ Príspevkov: 15 ] | |
|