Last active
June 28, 2016 09:41
-
-
Save PanJarda/79cea152b76de72db34c35e1942966d0 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
/* | |
* V jazyku c vytvořte funkci int uprav(char *soubor), která změní daný textový soubor tak, že každé velké písmeno | |
* bude nahraeno odpovídajícím malým pásmenem, každé malé písmeno bude nahrazeno odpovídajícím velkým písmenem a všechny | |
* ostatní znaky budou v souboru ponechány beze změny. | |
* Pro jednoduchost pracujte se soubory bez diakritiky. | |
* Návratovou hodnotu funkce lze použít pro oznámení nejruznějších chyb. | |
* Vytvořenou funkci řádně otestujte. | |
*/ | |
#include <stdio.h> | |
int uprav(char *soubor) { | |
// deklarace promennych | |
FILE *handle; | |
int c0; | |
int c; | |
// otevreme soubor | |
handle = fopen(soubor, "r+"); | |
// pokud se soubor nepodarilo otevrit, vratime chybovy kod 1 | |
if (!handle) | |
return 1; | |
// loop pres vsecky znaky | |
while ((c = fgetc(handle)) != EOF) { | |
c0 = c; | |
// prehodime case | |
if (64 < c && c < 91) | |
c += 32; | |
else if (96 < c && c < 123) | |
c = c - 32; | |
// pokud sme neprehodili case tak pokracujeme na dalsi znak | |
if (c0 == c) | |
continue; | |
// vratime se o znak zpet | |
fseek(handle, ftell(handle) - 1, SEEK_SET); | |
// zamenime znak v souboru | |
if (fputc(c, handle) == EOF) | |
return 1; | |
} | |
// zavreme soubor | |
fclose(handle); | |
return 0; | |
} | |
int main(int argc, char * argv[]) { | |
if (argc > 1) | |
return uprav(argv[1]); | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment