Advertisement
sellmmaahh

Izbaci Komentare-C string

Aug 25th, 2015
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.09 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.   int length(char *string)
  5. {
  6.     int len = 0;
  7.     while(*(string++) != '\0') len++;
  8.  
  9.     return len;
  10. }
  11.  
  12. void unos (char *s) {
  13.     char c;
  14.     while (c=getchar(),c!='\n') *(s++)=c;
  15.     *s='\0';
  16. }
  17.  
  18. void cut(char *string, int indeks, int len)
  19. {
  20.     int i;
  21.  
  22.     for(i = indeks; i <= length(string) - len; i++)
  23.     {
  24.         string[i] = string[i + len];
  25.     }
  26.  
  27. }
  28.  
  29. void IzbaciKomentare (char *s) {
  30.   int i;
  31.   int poc=0, kraj=0;
  32.   int duz=length(s);
  33.   for (i=0; i<duz; i++) {
  34.        if (s[i]=='/')
  35.         {
  36.             poc=i;
  37.             i++;
  38.        if (s[i]=='*')
  39.         {
  40.            i++;
  41.             while (s[i]!='*') i++;
  42.             i++;
  43.             if (s[i]=='/') kraj=i+1;
  44.         }
  45.        else if (s[i]=='/')
  46.             {
  47.             i++;
  48.        while (s[i]!='\0') i++;
  49.        kraj=i;
  50.            }
  51.  
  52.             cut (s,poc,kraj-poc);
  53.         }
  54.   }}
  55.  
  56.  
  57. int main () {
  58.     char c[100];
  59.     printf("Unesite recenicu: ");
  60.     unos(c);
  61.    IzbaciKomentare(c);
  62.     printf("Recenica bez komentara: %s",c);
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement