Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- void Unos(char *string, int duzina)
- {
- int i = 0;
- char c;
- while(c != '\n' || i > duzina) {
- c = getchar();
- string[i] = c;
- i++;
- }
- string[i-1] = '\0';
- }
- void IspisiRijec(char *string)
- {
- char *p = string;
- while(*p != '\0')
- {
- printf("%c", *p);
- p++;
- }
- }
- int BrojZnakova(char *string)
- {
- int brojac = 0;
- char *p = string;
- while(*p != '\0')
- {
- brojac++;
- p++;
- }
- return brojac;
- }
- int BrojSlova(char *string)
- {
- char *p = string;
- int brojac = 0;
- while(*p != '\0')
- {
- if((*p >='A' && *p <= 'Z') || (*p >= 'a' && *p <= 'z'))
- /*if((tolower(*p) >= 'a' && tolower(*p) <= 'z'));*/
- brojac++;
- p++;
- }
- return brojac;
- }
- int BrojCifri(char *string)
- {
- char *p = string;
- int brojac = 0;
- while(*p != '\0')
- {
- if(*p >= '0' && *p <= '9')
- brojac++;
- p++;
- }
- return brojac;
- }
- int BrojRijeci(char *s)
- {
- int brojac = 0;
- char *p = s;
- while(*p != '\0')
- {
- if(((*p >='A' && *p <= 'Z') || (*p >= 'a' && *p <= 'z')) && (p==s) || *(p ) ==' ')
- {
- while((tolower(*p) >= 'a' && tolower(*p) <= 'z'))
- p++;
- if(*p == ' ' || *p == '\0') brojac++;
- }
- p++;
- }
- return brojac;
- }
- int main()
- {
- char recenica[80];
- printf("Unesite recenicu od najvise 80 znakova: ");
- Unos(recenica, 80);
- IspisiRijec(recenica);
- printf("\n");
- printf("Broj znakova je: %d\n", BrojZnakova(recenica));
- printf("Broj slova: %d\n", BrojSlova(recenica));
- printf("Broj cifri: %d\n", BrojCifri(recenica));
- printf("Broj rijeci je: %d\n", BrojRijeci(recenica));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement