Advertisement
AntonioVillanueva

Patrones

Nov 10th, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.10 KB | None | 0 0
  1. // gcc -o patrones patrones.c -std=c99
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. #define PATRONES 41
  6.  
  7. void patronA (char * s){
  8.         void* address= s+10;
  9.         while (  (void*)s++ <address){if (*s!='*') {*s='*'; break;}}
  10. };
  11.  
  12. void patronB (char * s){
  13.         void* address= s;
  14.         s+=11;
  15.         while (  (void*)s-- >address) {if (*s!=' ') {*s=' '; break;}}
  16. };
  17.  
  18. void patronC (char * s){
  19.         void* address= s+10;
  20.         do{if (*s!=' ') {*s=' '; break;}}while (  (void*)s++ <address);
  21. };
  22.  
  23. void patronD (char * s){
  24.         void* address= s;
  25.         s+=11;
  26.        do{if (*s!='*') {*s='*'; break;}} while (  (void*)s-- >address) ;
  27. };
  28.  
  29. int main (){
  30.     char cadena []={"           "};
  31.  
  32.     for (int i=0;i<PATRONES;i++)
  33.     {
  34.  
  35.         if (i<10) {patronA (cadena);}
  36.         if (i>=11 && i<20) {patronB (cadena);}
  37.        
  38.         if (i==21) {memset (cadena,'*',sizeof (cadena));}//Llena de * para patron C
  39.        
  40.         if (i>=21 && i<32) {patronC (cadena);}
  41.         if (i>=32) {patronD(cadena);}
  42.          
  43.         printf ("%s \n",cadena);  
  44.     }
  45.         return 0;
  46. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement