Guest User

Untitled

a guest
Jan 16th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdlib>
  4. #include <ctype.h>
  5. #include <cstdio>
  6.  
  7. using namespace std;
  8.  
  9. string mocking_spongebob_generator(const string& text) {
  10. string result = "";
  11. for (unsigned i = 0; i < text.size(); ++i) {
  12. bool character_flag = rand() % 2;
  13. if (character_flag) {
  14. result += tolower(text[i]);
  15. } else {
  16. result += toupper(text[i]);
  17. }
  18. }
  19. return result;
  20. }
  21.  
  22. bool save_to_file(const string& text) {
  23. FILE *f = fopen("spongebob_generated.txt", "w");
  24. if (!f) return false;
  25. for (unsigned int i = 0; i < text.size(); ++i) {
  26. fprintf(f, "%c", text[i]);
  27. }
  28. fclose(f);
  29. return true;
  30. }
  31.  
  32. int main(int argc, char **argv) {
  33.  
  34. if (argc <= 1) {
  35. cerr << "no args";
  36. return 1;
  37. }
  38. srand(time(NULL));
  39. string text;
  40. for (int i = 1; i < argc; ++i) {
  41. text += argv[i];
  42. text += " ";
  43. }
  44. text = mocking_spongebob_generator(text);
  45. save_to_file(text);
  46. return 0;
  47. }
Add Comment
Please, Sign In to add comment