Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- unsigned int convert(char *hodnota)//funkce, ktera pretypuje N (vstup char a vystup unsigned int
- {
- unsigned int cislo=0,preteceni=0;
- int i=0;
- while(hodnota[i]!='\0')
- {
- if (hodnota[i]<'0' && hodnota[i]>'9') //osetreni, ze N je cislo (osetreni i pro to, ze cilo je kladne)
- {
- return 0;
- }
- hodnota[i]=hodnota[i]-'0'; //zaskani presne hodnoty cisla z nejake ascii hodnoty
- preteceni=cislo;
- cislo=cislo*10;
- cislo=cislo+hodnota[i]; //pokud uz proslo pripocte k 10tinasobku predchoziho cila prave nastene cislo
- i++;
- if(preteceni>cislo) //doslo k preteceni - jednicka vypadla ven a jede se od nuly
- {
- return 0; //kdyz vrati nulu - doslo k chybe (zde z duvodu preteceni)
- }
- }
- return cislo;
- }
- int dekomprimace(unsigned int N)
- {
- printf("Dekomprimace\n");
- printf("%d",N);
- int c;
- char *buffer = malloc((N+1) * sizeof(char));
- if(buffer==NULL) //ochrana proti nedodtatku paměti
- {
- return 1;
- }
- while((c = getchar()) != EOF)
- {
- if(isdigit(c)!=0)
- {
- int x;
- x = c - '0';
- for(unsigned i = 0; i < N; i++)
- {
- buffer[i] = getchar();
- if(isdigit(buffer[i])!=0)
- { //TADY JE PORTEBA DOPSAT OCHRANU, ABY NA VSTUPU NABYLY
- printf("Byla zadana 2 cisla vedle sebe - Musim pak prepsat na estate.eclwrong ;-)") ; //2 CISLA
- } //!!!!!! POZOR
- }
- for (;x>0;x--)
- {
- for(unsigned i = 0; i<N; i++)
- {
- putchar(buffer[i%N]);
- }
- }
- }
- else
- {
- putchar(c);
- }
- }
- return 0;
- }
- int main(int argc, char *argv[])
- {
- unsigned int N=(convert(argv[1]));
- dekomprimace(N);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement