Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- void unos (char *s) {
- char c;
- while (c=getchar(), c!='\n')
- *(s++)=c;
- *s='\0';
- }
- int length(char *string)
- {
- int len = 0;
- while(*(string++) != '\0') len++;
- return len;
- }
- int JeLiPraznina (char c) {
- if (c==' ' || c=='\n' || c=='\t') return 1;
- return 0;
- }
- int br_rijeci(char *string)
- {
- int i, br=0;
- for(i = 0; i < length(string); i++)
- {
- if(string[i] != ' ')
- {
- while(i < length(string) && string[i] != ' ')
- {
- i++;
- }
- br++;
- }
- }
- return br;
- }
- void cut(char *string, int indeks, int len)
- {
- int i;
- for(i = indeks; i <= length(string) - len; i++)
- {
- string[i] = string[i + len];
- }
- }
- void insert(char *string, char *word, int indeks)
- {
- int i;
- for(i = length(string) + length(word); i >= indeks + length(word); i--)
- {
- string[i] = string[i - length(word)];
- }
- for(i = 0; i < length(word); i++)
- {
- string[i + indeks] = word[i];
- }
- }
- void Whitespace (char *s) {
- int i;
- char rijec[]=" ";
- int duz=length(s);
- int poc=0, kraj=0;
- for (i=0; i<duz; i++) {
- if (JeLiPraznina(s[i]))
- {
- poc=i;
- while (JeLiPraznina(s[i])) {
- i++;
- }
- kraj=i;
- cut(s,poc,kraj-poc);
- insert(s,rijec,pocs);
- }
- }
- }
- int main () {
- char c[100];
- unos(c);
- printf("%s\n",c);
- Whitespace(c);
- printf("Nova rijec: %s",c);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement