Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define MAX_LENGTH 8
  5.  
  6. int main(){
  7. unsigned int string_len;
  8. unsigned int iterations = 0;
  9. char *ran_string = (char *)malloc(MAX_LENGTH * sizeof(char)+1);
  10. int i;
  11.  
  12. while(strcmp(ran_string, ":q!\n") != 0){
  13. iterations++;
  14. string_len = rand() % MAX_LENGTH;
  15.  
  16. for (i = 0; i < string_len; ++i) {
  17. ran_string[i] = rand() % 127;
  18. }
  19. ran_string[++i] = '\0';
  20. }
  21. printf("Completed after %d iterations.", iterations);
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement