/*
* uzivatelske retezcove funkce
*/
#include <stdio.h>
#include <stdlib.h>
char radek[256], *p;
char *SmazEOLN(char *s) { // funkce vraci adresu zpracovavaneho retezce
char *pom = s;
while (*pom != '\0') pom++;
pom--;
if (*pom == '\n') *pom = '\0';
return s;
}
char *UpString(char *s) {
char *pom = s;
while (*pom != '\0') {
if (*pom>='a' && *pom<='z') *pom -= 'a'-'A';
pom++;
}
return s;
}
int PocetMezer(const char *s) { // parametr funkce je pouze pro CTENI
char *pom = (char *)s;
int n=0;
while (*pom != '\0') {
if (*pom ==' ') n++;
pom++;
}
return n;
}
//
// Tato funkce sama alokuje potrebne pametove misto
// - ne uplne standardni chovani funkce - vzdy popiste v komentari
//
char *VytvorRetezec(int pocet, char znak) {
char *pom;
int i;
pom = malloc(pocet+1);
for (i=0; i<pocet; i++) *(pom+i) = znak;
*(pom+pocet) = '\0';
return pom;
}
int main(int argc, char *argv[]){
int i;
printf("pocet parametru programu = %d \n", argc);
for (i=0;i<argc;i++) printf("%d.parametr = %s\n", i,argv[i]);
while (fgets(radek,256,stdin)!=NULL){
SmazEOLN(radek);
UpString(radek);
printf("'%s'\n", radek);
printf("pocet mezer = %d \n", PocetMezer(radek));
p = VytvorRetezec(30,'-');
printf("%s\n",p);
}
return 0;
}