Advertisement
sellmmaahh

Whitespace-string-pok1

Aug 25th, 2015
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.68 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void unos (char *s) {
  5.     char c;
  6.     while (c=getchar(), c!='\n')
  7.         *(s++)=c;
  8.     *s='\0';
  9. }
  10.  
  11. int length(char *string)
  12. {
  13.     int len = 0;
  14.     while(*(string++) != '\0') len++;
  15.  
  16.     return len;
  17. }
  18. int JeLiPraznina (char c) {
  19.     if (c==' ' || c=='\n' || c=='\t') return 1;
  20.     return 0;
  21. }
  22.  
  23. int br_rijeci(char *string)
  24. {
  25.     int i, br=0;
  26.  
  27.     for(i = 0; i < length(string); i++)
  28.     {
  29.         if(string[i] != ' ')
  30.         {
  31.  
  32.             while(i < length(string) && string[i] != ' ')
  33.             {
  34.                i++;
  35.             }
  36.             br++;
  37.         }
  38.     }
  39.  
  40.     return br;
  41. }
  42.  
  43. void cut(char *string, int indeks, int len)
  44. {
  45.     int i;
  46.  
  47.     for(i = indeks; i <= length(string) - len; i++)
  48.     {
  49.         string[i] = string[i + len];
  50.     }
  51.  
  52. }
  53. void insert(char *string, char *word, int indeks)
  54. {
  55.     int i;
  56.     for(i = length(string) + length(word); i >= indeks + length(word); i--)
  57.     {
  58.         string[i] = string[i - length(word)];
  59.     }
  60.  
  61.     for(i = 0; i < length(word); i++)
  62.     {
  63.         string[i + indeks] = word[i];
  64.     }
  65. }
  66.  
  67. void Whitespace (char *s) {
  68.     int i;
  69.     char rijec[]=" ";
  70.     int duz=length(s);
  71.     int poc=0, kraj=0;
  72.     for (i=0; i<duz; i++) {
  73.             if (JeLiPraznina(s[i]))
  74.                {
  75.                 poc=i;
  76.             while (JeLiPraznina(s[i])) {
  77.                     i++;
  78.             }
  79.             kraj=i;
  80.                cut(s,poc,kraj-poc);
  81.                insert(s,rijec,pocs);
  82.           }
  83.  
  84.     }
  85. }
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92. int main () {
  93.     char c[100];
  94.     unos(c);
  95.     printf("%s\n",c);
  96.   Whitespace(c);
  97.     printf("Nova rijec: %s",c);
  98.     return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement