Advertisement
dllbridge

Untitled

Oct 21st, 2024
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.90 KB | None | 0 0
  1.  
  2.  
  3.  
  4. #include   <stdio.h>
  5. #include  <string.h>
  6. #include    <time.h>
  7. #include  <stdlib.h>
  8.  
  9.  
  10.  
  11. char* gen_word();
  12.  
  13. char* gen_sentence();  
  14.  
  15.  
  16. ///////////////////////////////////////////////////////////////
  17. int main()                                                   //
  18. {
  19.    
  20.     srand( time(0));
  21.    
  22.     for(int i = 0; i < 10; i++)
  23.     {
  24.         printf("%s\n", gen_word() );
  25.     }   printf(" - - - - - - - \n");
  26.  
  27.     for(int i = 0; i < 10; i++)
  28.     {    
  29.         printf("%s\n", gen_sentence() );
  30.     }
  31. }
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39. ///////////////////////////////////////////////////////////////
  40. char  gen_symb()                                             //
  41. {
  42.      
  43.       char c = 97 + rand()%26;
  44.      
  45. return c;      
  46. }
  47.  
  48.  
  49. ///////////////////////////////////////////////////////////////
  50. char* gen_word()                                             //
  51. {
  52.      
  53.       int n = 1 + rand() % 11;
  54.      
  55.       static char sz[99];
  56.      
  57.       sz[0] = 0;
  58.      
  59.       for(int i = 0; i <= n; i++)
  60.       {
  61.              
  62.           if(i == n) sz[i] = 0;
  63.           else       sz[i] = gen_symb();
  64.       }
  65.      
  66. return sz;      
  67. }
  68.  
  69.  
  70.  
  71. ///////////////////////////////////////////////////////////////
  72. char* gen_sentence()                                         //
  73. {
  74.      
  75.       int n = 3 + rand() % 10,
  76.          _n = 0,
  77.           i = 0;
  78.          
  79.       static char  sz[999];
  80.              char *psz;
  81.      
  82.      
  83.       memset(sz, 0, 199);                                     // заполнить первые 199 байт символом
  84.      
  85.       while(_n < n)
  86.       {
  87.           psz = gen_word();
  88.              
  89.           strcat(&sz[i], psz);      _n ++;    if(_n == 1) sz[0] -= 32;  
  90.          
  91.           i += strlen(psz);
  92.          
  93.           sz[i] = 32;                i ++;    
  94.       }      
  95.      
  96.       sz[i-1] = '.';
  97.       sz[i  ] =   0;
  98.  
  99. return sz;      
  100. }
  101.  
  102.  
  103.  
  104.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement