Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <time.h>
- #include <stdlib.h>
- char* gen_word();
- char* gen_sentence();
- ///////////////////////////////////////////////////////////////
- int main() //
- {
- srand( time(0));
- for(int i = 0; i < 10; i++)
- {
- printf("%s\n", gen_word() );
- } printf(" - - - - - - - \n");
- for(int i = 0; i < 10; i++)
- {
- printf("%s\n", gen_sentence() );
- }
- }
- ///////////////////////////////////////////////////////////////
- char gen_symb() //
- {
- char c = 97 + rand()%26;
- return c;
- }
- ///////////////////////////////////////////////////////////////
- char* gen_word() //
- {
- int n = 1 + rand() % 11;
- static char sz[99];
- sz[0] = 0;
- for(int i = 0; i <= n; i++)
- {
- if(i == n) sz[i] = 0;
- else sz[i] = gen_symb();
- }
- return sz;
- }
- ///////////////////////////////////////////////////////////////
- char* gen_sentence() //
- {
- int n = 3 + rand() % 10,
- _n = 0,
- i = 0;
- static char sz[999];
- char *psz;
- memset(sz, 0, 199); // заполнить первые 199 байт символом
- while(_n < n)
- {
- psz = gen_word();
- strcat(&sz[i], psz); _n ++; if(_n == 1) sz[0] -= 32;
- i += strlen(psz);
- sz[i] = 32; i ++;
- }
- sz[i-1] = '.';
- sz[i ] = 0;
- return sz;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement