Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. #include "stdio.h"
  2. #include "string.h"
  3. #include <malloc.h>
  4. int isV(char s);
  5. int isL(char s);
  6. int isC(char s);
  7. int sillabs(char* s);
  8. char* sillaba(char* s);
  9.  
  10. int main()
  11. {
  12.     char* word = "ciao";
  13.     printf("%s\n",sillaba("evadererere"));
  14. }
  15.  
  16.  char* sillaba(char* s) {
  17.  
  18.      int sillabe = sillabs(s);
  19.      char* sp = malloc(sizeof(char)*(strlen(s)+sillabe - 1));
  20.      char* p = sp;
  21.          int l = 0;
  22.      if (isV(*(s))) {
  23.          *sp = *s;
  24.          *(sp + 1) = '-';
  25.          l++;
  26.          s++;
  27.          sp += 1 + l;
  28.      }
  29.  
  30.      for (; *s; s++, sp++) {
  31.          if (isC(*s)) {
  32.              if (isV(*(s + 1))) {
  33.                  *(sp) = *s;
  34.                  *(sp + 1) = *(s+1);
  35.                  if (*(s + 2) == '\0') {
  36.                      *(sp + 2) = '\0';
  37.                      contaSillabe(p);
  38.                      return p;
  39.                  }
  40.                  *(sp + 2) = '-';
  41.                  l++;
  42.                  sp += 2;
  43.                  s++;
  44.              }
  45.          }
  46.      }
  47.      contaSillabe(p);
  48.      return p;
  49.  
  50.  }
  51.  int isV(char s) {
  52.      char* vocals = "aeiou";
  53.      if (!isL(s)) return 0;
  54.      for (; *vocals; vocals++) if (s==*vocals) return 1;
  55.      return 0;
  56.  }
  57.  int isC(char s) {
  58.      return !isV(s) && isL(s);
  59.  }
  60.  int isL(char s) {
  61.      if ((s <= 'Z' && s >= 'A') || (s <= 'z'&&s >='a' ))return 1;
  62.      else return 0;
  63.  }
  64.  int sillabs(char* s) {
  65.      int sillabe = 0;
  66.      if (isV(*(s))) sillabe++;
  67.      for (; *s; s++) {
  68.          if (isC(*s)) {
  69.              if (isV(*(s + 1)) || *(s + 1) == '\0') {
  70.                  sillabe++;
  71.              }
  72.  
  73.          }
  74.      }
  75.      return sillabe;
  76.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement