Advertisement
sellmmaahh

Izbaci Ntu Rijec-String

Aug 25th, 2015
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.33 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.  
  19. int br_rijeci(char *string)
  20. {
  21.     int i, br=0;
  22.  
  23.     for(i = 0; i < length(string); i++)
  24.     {
  25.         if(string[i] != ' ')
  26.         {
  27.  
  28.             while(i < length(string) && string[i] != ' ')
  29.             {
  30.                i++;
  31.             }
  32.             br++;
  33.         }
  34.     }
  35.  
  36.     return br;
  37. }
  38.  
  39. void cut(char *string, int indeks, int len)
  40. {
  41.     int i;
  42.  
  43.     for(i = indeks; i <= length(string) - len; i++)
  44.     {
  45.         string[i] = string[i + len];
  46.     }
  47.  
  48. }
  49.  
  50. void IzbaciNtu (char *s, int n) {
  51.     if (n<1 && n>br_rijeci(s)) return 0;
  52.     int duz=length(s);
  53.  
  54.       int i, br=0, poc=0, kraj=0;
  55.        for(i = 0; i <duz; i++)
  56.     {
  57.         if(s[i] != ' ')
  58.         {      poc=i;
  59.  
  60.             while(i < duz && s[i] != ' ')
  61.             {
  62.                i++;
  63.             }
  64.               kraj=i;
  65.             br++;
  66.         }
  67.             if (br==n) {
  68.              cut(s,poc, kraj-poc+1);
  69.  
  70.             }
  71.     }}
  72.  
  73.  
  74. int main () {
  75.     char c[100];
  76.     unos(c);
  77.     printf("%s\n",c);
  78.     IzbaciNtu(c,2);
  79.     printf("Nova rijec: %s",c);
  80.     return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement